Currently, the mainstream installation of PHP operating environment on the market is installed through software package tools, cloud platform management tools, one-click installation packages, etc. However, sometimes we want to manually install the PHP operating environment for a better understanding. PHP working principle and the details of interactive communication with the server. Here's how to manually install the PHP running environment.
Before installing PHP, you need to install some dependent packages, such as web servers, databases, development tools, etc. Common web servers include Apache and Nginx, databases include MySQL, SQLite, etc., and development tools include Vim, Emacs, etc. We can use the system's own package manager to install, or we can download the installation package from the official website and install it manually.
Download the required PHP compressed package from the PHP official website https://www.php.net/downloads.php and select Web Server compatible version. Usually, two versions of Apache and Nginx are provided. It should be noted that different versions have different configuration and compilation options. If you choose the wrong one, PHP will not be able to run.
Decompress the downloaded PHP compressed package and execute the following command:
tar -xzvf php-x.y.z.tar.gz
Among them, x.y.z is the PHP version number, after decompression You will get a directory of php-x.y.z.
After entering the php-x.y.z directory, execute the following command to configure:
./configure --prefix=/usr/local/php [--with-apxs2=/usr/local/apache/bin/apxs]
Among them, ./configure is the execution configuration Script, --prefix specifies the installation directory, --with-apxs2 specifies the APXS path of Apache. If you use Nginx as the web server, you do not need to specify this option.
When executing the above command, you may be prompted that relevant dependencies are missing and you need to install them according to the prompts.
After the configuration is completed, execute the following command to compile and install:
make make install
The make command is used to compile the source code, make install The command is used to install the compiled files to the specified location.
After PHP is installed, some configuration is required to run properly. First, enter the bin directory under the PHP installation directory and execute the following command:
cp php.ini-development /usr/local/php/lib/php.ini
Rename php.ini-development to php.ini and copy it to the PHP configuration directory.
Secondly, add the following directive to the web server's configuration file (such as Apache's httpd.conf):
AddType application/x-httpd-php .php
This directive tells the web server to use the file with the suffix php as a PHP script deal with.
Finally, start the web server and access the PHP file. If the page can display PHP information normally, it means that the manual installation of the PHP running environment is successful.
This article introduces the method and process of manually installing the PHP running environment. It requires a certain knowledge of Linux system and compilation and is suitable for use in development and debugging environments. In a production environment, you can use one-click installation packages to quickly build a PHP operating environment to improve efficiency and security.
The above is the detailed content of How to manually install the php runtime environment. For more information, please follow other related articles on the PHP Chinese website!