felayman-----PHP environment setup_PHP tutorial
PHP is a server-side embedded scripting language. It is a server-side, cross-platform, object-oriented, HTML-embedded scripting language. This chapter will introduce readers to the establishment of a PHP development environment, common configuration problems and solutions. By studying this chapter, readers can learn the following contents.
Change verification code
: Windows - AppserV integrated installation package to build PHP environment
: Linux - XAMPP integrated installation package to build PHP environment
: Key configuration information of PHP development environment
: Solve common configuration problems of PHP
1.1 PHP environment setup
1.1.1 AppServ—Windows version PHP integrated installation package
AppServ packages server software and tools such as Apache, PHP, MySQL and phpMyAdmin after they are installed and configured. Developers only need to download the software from the website and then install it to quickly build a PHP development environment. Very suitable for beginners.
Note: When using AppServ to build a PHP development environment, you must ensure that Apache, PHP and MySQL are not installed in the system. Otherwise, uninstall these software first and then apply AppServ.
The following explains the specific steps to build a PHP development environment using the AppServ integrated installation package:
(1) Double-click the AppServ-win32-2.5.10.exe file to open the AppServ startup page as shown in Figure 1.1.
(2) Click the Next button in Figure 1.1 to open the AppServ installation agreement page as shown in Figure 1.2.
(3) Click the I Agree button in Figure 1.2 to open the page shown in Figure 1.3. Set the installation path of AppServ (the default installation path is generally: E:AppServ). After the AppServ installation is completed, Apache, MySQL, and PHP will be stored in this directory in the form of subdirectories.

(4) Click the Next button in Figure 1.3 to open the page shown in Figure 1.4. Select programs and components to install (select all by default).
Note: In the operation steps in Figure 1.4, if the MySQL database is already installed on this machine, you can uncheck the MySQL Database option here and still use the MySQL database that already exists on this machine.
(5) Click the Next button in Figure 1.4 to open the page shown in Figure 1.5. Fill in the computer name, add an email address, and set the Apache port number. The default is port 80.
Tips: The setting of the Apache server port number is directly related to whether the Apache server can start normally. If port 80 on this machine is occupied by IIS or Thunder, then you need to modify the port number of Apache, or modify the port number of IIS or Thunder to complete the configuration of the Apache server. If a port conflict occurs, the installation will fail and the Apache service will not start.
(6) Click the Next button in Figure 1.5 to open the page shown in Figure 1.6. Set the login password and character set of the MySQL database root user.
Tip: To set the character set of MySQL database, you can choose UTF-8, GBK or GB2312. Here, the character set is set to "UTF-8 Unicode", which means that the character set of the MySQL database will use UTF8 encoding.

Note: The password for the MySQL database root user set in Figure 1.6 must be remembered because the program must use this password when connecting to the database.
When executing the program, you need to change the password to connect to the database. If you forget to set the password during installation, the most direct and effective solution is to reinstall AppServ.
(7) Click the Install button in Figure 1.6 to start the installation, as shown in Figure 1.7.

(8) After the installation is completed, you can start the Apache and MySQL services in the AppServ related operation list in the start menu, as shown in Figure 1.8.

1.2 Key configuration information of PHP development environment
The configuration method of the PHP development environment was introduced earlier. In addition to the installation steps themselves, the configuration of PHP and the server is also very important. The following will mainly introduce the configuration of PHP and Apache server.
1.2.1 Basic configuration of Apache server
The setting file of the Apache server is located in the /usr/local/apache/conf/ directory in the Linux operating system (located in "/etc/httpd/conf" in the Windows operating system). Basically, the following 3 configuration files are used to configure the behavior of the Apache server.
t access.conf: used to configure server access permissions and control access restrictions for different users and computers.
t httpd.conf: used to set the basic environment for server startup.
t srm.conf: Mainly used for setting file resources.
Tips: http.conf is the configuration file of the Apache server. Its commonly used configurations include: the port number of the Apache server, the access path of the server and pseudo-static settings.
ServerName localhost:80
DocumentRoot "/xampp/htdocs"
LoadModule rewrite_module modules/mod_rewrite.so
1.2.2 Basic configuration of PHP.INI file
The php.ini file is a configuration file that PHP automatically reads when it starts. php.ini is an ASCLL text file, divided into multiple parts, each part includes related parameters. The name of each part is placed in the first square bracket, followed by the name and number, each name on its own line. Use regular PHP code, which is very sensitive to parameter names and cannot contain spaces, but parameters can be numbers, strings or Boolean logical numbers. A semicolon is placed at the beginning of each line as a designation mark, which makes it easy to choose to use or not use these features of PHP without having to delete the line. Commenting out a feature (that is, adding a semicolon) will not compile and execute the line. Each time you modify the php.ini file, you must restart the Apache server for the new settings to take effect.
Tips: php.ini is the PHP configuration file, used to load various function libraries, set error levels, set server time, etc. In the Linux operating system, php.ini is stored in the /opt/lampp/etc/php.ini folder, while in the Windwos operating system, php.ini is stored in the windows file on the system disk. The basic configuration of the php.ini file is shown in Table 1.1.
Table 1.1 Basic configuration of php.ini file
|
Description | Default value | |||||||||||||||||||||||||||||||||
error_reporting | Set the level of error handling. Recommended values are E_ALL & ~E_NOTICE & ~E_STRICT, which displays all error messages except reminders and encoding standardization warnings. | E_ALL & ~E_NOTICE & ~E_STRICT | |||||||||||||||||||||||||||||||||
register_globals | Normally, this variable can be set to Off, which can provide more secure protection against script attacks through forms | register_globals = On | |||||||||||||||||||||||||||||||||
include_path | Set the PHP search path. This parameter can receive a series of directories. When PHP encounters a file prompt without a path, it will automatically detect these directories. It should be noted that when some options allow multiple values, the system list separator should be used. Under Windows, use the semicolon ";" Use colon ":" under Linux | ; UNIX: "/path1:/path2" ;include_path = ".:/php/includes" ; Windows: "path1;path2" ;include_path = ".;c:phpincludes" | |||||||||||||||||||||||||||||||||
extension_dir | Specify the directory of PHP’s dynamic link extension library | Under the "ext" directory | |||||||||||||||||||||||||||||||||
extension | Specify the dynamic link extension library loaded when PHP starts. Please refer to Table 1.2 for common PHP extension libraries and their descriptions. | PHP’s common extension libraries are commented after the initial installation and configuration, and readers need to manually change them | |||||||||||||||||||||||||||||||||
file_uploads | Set whether to allow file upload via HTTP | file_uploads=On | |||||||||||||||||||||||||||||||||
upload_tmp_dir | Set the temporary directory when uploading files via HTTP. If it is empty, the system's temporary directory will be used | upload_tmp_dir=empty | |||||||||||||||||||||||||||||||||
upload_max_filesize | Set the size of files allowed to be uploaded, such as "50M", the unit must be filled in | upload_max_filesize=2M | |||||||||||||||||||||||||||||||||
post_max_size | Control the maximum capacity that PHP can receive during a form submission using the POST method. To upload larger files, this value must be greater than the value of upload_max_filesize. If upload_max_filesize=10M, then the value of upload_max_filesize must be greater than 10M | post_max_size = 8M | |||||||||||||||||||||||||||||||||
max_input_time | Limit the time of receiving data through POST, GET and PUT in seconds | max_input_time = 60 |
Table 1.2 PHP common extension libraries and their descriptions
|
Description | ||||||||||||||||||||||||||||||||||
php_ftp.dll | Supports FTP function library, which can implement standard transfer protocol (FTP) between client and server | ||||||||||||||||||||||||||||||||||
php_gd2.dll | Supports image processing function library, supports various image formats such as .gif, .jpg, .png, etc. | ||||||||||||||||||||||||||||||||||
php_imap.dll | Support imap email processing function library | ||||||||||||||||||||||||||||||||||
php_mssql.dll | Support MsSQL database | ||||||||||||||||||||||||||||||||||
php_msql.dll | Support mSQL database | ||||||||||||||||||||||||||||||||||
php_MySQL.dll | Support MySQL database | ||||||||||||||||||||||||||||||||||
php_oracle.dll | Support Oracle database | ||||||||||||||||||||||||||||||||||
php_pdf.dll | Support PDF file processing function library | ||||||||||||||||||||||||||||||||||
php_sockets.dll | Supports Sockets processing function library | ||||||||||||||||||||||||||||||||||
php_zlib.dll | Support zlib file compression function library | ||||||||||||||||||||||||||||||||||
php_pdo.dll | Supports PDO database abstraction layer | ||||||||||||||||||||||||||||||||||
php_pdo_mysql.dll | Support MySQL database | ||||||||||||||||||||||||||||||||||
php_pdo_mssql.dll | Supports MS SQL Server database | ||||||||||||||||||||||||||||||||||
php_pdo_oci8.dll | Support Oracle database | ||||||||||||||||||||||||||||||||||
php_pdo_odbc.dll | Support ODBC database | ||||||||||||||||||||||||||||||||||
php_pdo_pgsql.dll | Support PGSQL database |
1.3 Solve common configuration problems of PHP
Program running errors are the most troublesome problem for many programmers. The following introduces common configuration problems of PHP. By studying this section, you can distinguish which errors are caused by improper configuration of the PHP environment, thereby avoiding unnecessary waste of time and resources and completing the development of Web applications efficiently.
1.3.1 Resolve Apache server port conflict
The default port number of IIS is 80, which is the same as the default port number of the Apache server. Since the same port number 80 is used, a conflict will occur when running the web page.
If IIS is installed on the user's machine, you need to modify the default port of IIS, otherwise the Apache server will not work properly. To change the default listening port 80 of IIS, you can set it in the IIS manager or stop the IIS service.
Users can also change the default port number when installing the Apache server, thereby solving the conflict problem caused by two servers sharing the same port number.
Tips: If you set the Apache port number to 82 when building a PHP environment, then when accessing the project through a browser, you should enter http://127.0.0.1:82/ or http://localhost: 82/.
1.3.2 Set the current system time of PHP
Due to the rewriting of the date() function in PHP 5.0, the current date and time function is 8 hours less than the system time. The default setting in the PHP language is standard Greenwich Time (that is, the zero time zone is used), so to obtain the current local time, you must change the time zone setting in the PHP language. Here’s how:
In the php.ini file, find the ";date.timezone=" option under [date], modify it to "date.timezone =Asia/Hong_Kong", and then restart the Apache server.
After the setting is completed, there will be no time difference problem when outputting the current time of the system.
1.3.3 Add PHP extension module
Adding a PHP extension module is also called a dynamic extension, which is used to dynamically load a module. It contains an instruction: extension.
Under the Windows operating system, the method of loading modules is as follows. Open the php.ini file, navigate to the following location, remove the semicolon in front of ;tension=php_java.dll, save it and restart the Apache server to complete the loading operation of the extension module.
;tension=php_java.dll
Under the Linux operating system, the method of loading modules is as follows.
extension=php_java.so
It should be noted that loading only this line of code does not necessarily enable the relevant expansion packs. Sometimes it is also necessary to ensure that the relevant software is installed in the operating system. For example: To enable java support, you need to install JDK.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Windows Recovery Environment (WinRE) is an environment used to repair Windows operating system errors. After entering WinRE, you can perform system restore, factory reset, uninstall updates, etc. If you are unable to boot into WinRE, this article will guide you through fixes to resolve the issue. Unable to boot into the Windows Recovery Environment If you cannot boot into the Windows Recovery Environment, use the fixes provided below: Check the status of the Windows Recovery Environment Use other methods to enter the Windows Recovery Environment Did you accidentally delete the Windows Recovery Partition? Perform an in-place upgrade or clean installation of Windows below, we have explained all these fixes in detail. 1] Check Wi

In this article, we will learn about the differences between Python and Anaconda. What is Python? Python is an open source language that places great emphasis on making the code easy to read and understand by indenting lines and providing whitespace. Python's flexibility and ease of use make it ideal for a variety of applications, including but not limited to scientific computing, artificial intelligence, and data science, as well as creating and developing online applications. When Python is tested, it is immediately translated into machine language because it is an interpreted language. Some languages, such as C++, require compilation to be understood. Proficiency in Python is an important advantage because it is very easy to understand, develop, execute and read. This makes Python

PHP integrated environment packages include: 1. PhpStorm, a powerful PHP integrated environment; 2. Eclipse, an open source integrated development environment; 3. Visual Studio Code, a lightweight open source code editor; 4. Sublime Text, a A popular text editor, widely used in various programming languages; 5. NetBeans, an integrated development environment developed by the Apache Software Foundation; 6. Zend Studio, an integrated development environment designed for PHP developers.

Setting environment variables on Windows 11 can help you customize your system, run scripts, and configure applications. In this guide, we'll discuss three methods along with step-by-step instructions so you can configure your system to your liking. There are three types of environment variables System environment variables – Global variables are the lowest priority and are accessible to all users and applications on Windows and are typically used to define system-wide settings. User Environment Variables – Higher priority, these variables only apply to the current user and process running under that account, and are set by the user or application running under that account. Process environment variables – have the highest priority, they are temporary and apply to the current process and its sub-processes, providing the program

Common problems and solutions for Laravel environment configuration file .env When using the Laravel framework to develop projects, the environment configuration file .env is very important. It contains key configuration information of the project, such as database connection information, application keys, etc. However, sometimes there are some common problems when configuring the .env file. This article will introduce these problems and provide solutions, and attach specific code examples for reference. Problem 1: Unable to read the .env file when we have configured the .env file

Go language environment configuration method: 1. Download the go language compiler and double-click to run the installation program; 2. Accept the license agreement and click next; 3. Set the installation directory and click OK; 4. After the installation is completed, change the go installation directory Just add the bin directory to the environment variable.

Deleting Conda Environments with One Click: Tips for Quickly Cleaning Up Useless Environments With the rapid development of data science and machine learning, the need to use Python for development and analysis is becoming stronger and stronger. Conda, as a popular Python package manager and environment management tool, is widely used in project development and environment configuration. However, over time, we often leave many useless Conda environments on the computer, which not only wastes disk space, but may also lead to environment clutter and unnecessary trouble. This article will introduce

The difference and connection between the pipenv environment and the virtual environment requires specific code examples. With the increasing popularity of Python, more and more developers are using virtual environments in Python projects to isolate the dependent libraries of different projects. The virtual environment can ensure that the Python libraries and their versions that the project depends on are properly managed to avoid various conflicts and version inconsistencies. However, in the past, using virtual environments required third-party libraries such as virtualenv and virtualenvwrapper. soon
