Home > Article > Backend Development > Analysis of the compilation and installation methods of Nginx and PHP
Nginx and PHP are two commonly used open source software, used to build web servers and process dynamic web content. This article will introduce the compilation and installation methods of Nginx and PHP, and provide specific code examples.
Nginx is a high-performance HTTP and reverse proxy server. Installing Nginx can help us quickly build a stable and efficient Web server.
First, we need to download the latest Nginx source code package from the Nginx official website (https://nginx.org). At the time of writing, the latest version is nginx-1.19.8.tar.gz.
Execute the following command in the terminal to decompress the source code package to the specified directory:
tar -zxvf nginx-1.19.8.tar.gz -C /usr/local/src
Enter the decompressed directory and execute The configure command configures the compilation parameters:
cd /usr/local/src/nginx-1.19.8 ./configure --prefix=/usr/local/nginx
Execute the make command to compile:
make
Then execute the make install command to install:
make install
After the installation is complete, execute the following command to start the Nginx service:
/usr/local/nginx/sbin/nginx
PHP is a popular A server-side scripting language, often used with Nginx to process dynamic web content. The following describes how to compile and install PHP.
Visit the PHP official website (https://www.php.net) to download the latest PHP source code package. At the time of writing, the latest version is php-7.4.16.tar.gz.
Execute the following command to decompress the source code package:
tar -zxvf php-7.4.16.tar.gz -C /usr/local/src
Enter the decompressed directory and execute the configure command to configure the compilation parameters:
cd /usr/local/src/php-7.4.16 ./configure --prefix=/usr/local/php --with-openssl --with-zlib
Execute the make command to compile:
make
Then execute the make install command to install:
make install
Add the following configuration in the Nginx configuration file to support PHP:
location ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; include fastcgi_params; }
Execute the following command to restart Nginx and PHP -FPM service:
/usr/local/nginx/sbin/nginx -s reload /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
Through the introduction of this article, we have learned the compilation and installation methods of Nginx and PHP, and learned how to configure them to work together. Through reasonable configuration and management, we can build a high-performance and stable web server to provide users with a better access experience.
The above is the detailed content of Analysis of the compilation and installation methods of Nginx and PHP. For more information, please follow other related articles on the PHP Chinese website!