With the continuous development of Internet technology, more and more people are beginning to understand and learn web development. In web development, PHP is a very important language because PHP can be used to develop dynamic websites, e-commerce and other applications. This article will introduce how to manually build an environment for the PHP decompressed version.
1. Preparation
Before we start building, we need to prepare the environment. First you need to download the decompressed version of php. Here we take php7.2 as an example. You can download it directly from the official website (https://www.php.net/downloads.php) and unzip it to any directory.
1. Set up in the Windows operating system
The setup in the Windows operating system is relatively simple and only requires an integrated tool XAMPP. XAMPP is a free open source service software with built-in services such as Apache, MySQL and PHP. It can be used to build a PHP environment. The specific steps are as follows:
1.1 Download and install XAMPP
First, you need Download the appropriate version of XAMPP from the official website (https://www.apachefriends.org/download.html) and install it locally. After successful installation, start the Apache and MySQL services in the control panel.
1.2 Configure the PHP decompressed version
Copy the PHP decompressed version folder to the root directory of XAMPP (the default directory is C:\xampp). On the XAMPP main page, click the "Configure" button and select "PHP (php.ini)". In the opened file, modify the following configuration:
;extension_dir = "./"
extension_dir="C:\xampp\php\ext"
error_reporting=E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING
date.timezone = "PRC"
upload_max_filesize=20M
post_max_size=20M
The above configuration can be adjusted as needed, mainly completing the following operations:
1.3 Restart the Apache server
After the configuration is completed, you need to restart the Apache server to make the configuration file take effect. On the XAMPP main page, click "Manage Services", select "Apache", and then click "Restart".
2. Set up in Linux operating system
To build a PHP environment in Linux operating system, you need to install the Apache server, MySQL database and PHP parser first, and then configure them. This article takes CentOS as an example. The steps are as follows:
2.1 Install the necessary tools
Execute the following command in the terminal to install the necessary tools:
yum -y install wget curl tar zip unzip
2.2 Install the Apache server
Execute the following command in the terminal to install the Apache server:
yum -y install httpd
After the installation is completed, Start the Apache service and set it to start automatically at boot:
systemctl start httpd.service
systemctl enable httpd.service
2.3 Install the MySQL database and PHP parser
in Execute the following commands in the terminal to install the MySQL database and PHP parser:
yum -y install mariadb-server mariadb php php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
After the installation is complete, start the MySQL service and set it to start automatically at boot:
systemctl start mariadb.service
systemctl enable mariadb.service
2.4 Configure PHP decoder
Copy the PHP decompressed version folder to the specified location and configure the environment variable:
cp -r /path/to/php-7.2.33 /usr/local/php-7.2.33
vi /etc/profile
In the opened file, add the following content:
export PHP_HOME=/usr/local/php-7.2.33
export PATH=$PATH:$PHP_HOME/bin
Save and exit the file, then execute the following command to make the configuration take effect:
source /etc/profile
2.5 Configure PHP decompressed version
Enter the PHP decompressed version directory, rename php.ini-development to php.ini, and modify the following configuration as needed:
cgi.fix_pathinfo=0
display_errors=Off
log_errors=On
error_log=/var/log/php_error.log
date.timezone=Asia/Shanghai
The above configuration can be adjusted as needed, and the main operations are as follows:
After saving the changes, copy the php.ini file to the /etc/php.ini directory:
cp php.ini /etc/php.ini
2.6 Restart the Apache server
After the configuration is completed, you need to restart the Apache server to make the configuration file take effect. Execute the following command in the terminal:
systemctl restart httpd.service
2. Whether the test environment is set up successfully
Enter localhost or 127.0.0.1 in the browser to check whether The Apache default page appears. If it appears, it means that the Apache server is running normally. Next, you can test whether the PHP decompressed version environment is successfully established by creating an info.php file. The content is as follows:
phpinfo();
?>
Put this file in the root directory of the Apache server (the default directory is htdocs), enter localhost/info.php or 127.0.0.1/info.php in the browser, and check whether PHP version-related information appears. If it appears, it means that the PHP decompressed version environment has been set up successfully.
3. Summary
This article introduces how to manually set up the environment for the PHP decompression version, mainly including Windows operating system and Linux operating system. Through the above operations, you can quickly build a PHP environment and develop related websites and applications. If you encounter problems, you can refer to the official documentation, or you can search on the Internet to solve the problem.
The above is the detailed content of How to manually set up the environment for the PHP decompressed version. For more information, please follow other related articles on the PHP Chinese website!