Home  >  Article  >  Backend Development  >  Analysis of the compilation and installation methods of Nginx and PHP

Analysis of the compilation and installation methods of Nginx and PHP

PHPz
PHPzOriginal
2024-02-27 18:09:041113browse

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.

1. Nginx compilation and installation method

Nginx is a high-performance HTTP and reverse proxy server. Installing Nginx can help us quickly build a stable and efficient Web server.

1. Download the Nginx source code package

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.

2. Decompress the source code package and configure compilation parameters

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

3. Compile and install Nginx

Execute the make command to compile:

make

Then execute the make install command to install:

make install

4. Start the Nginx service

After the installation is complete, execute the following command to start the Nginx service:

/usr/local/nginx/sbin/nginx

2. PHP compilation and installation method

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.

1. Download the PHP source code package

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.

2. Unzip the source code package and configure the compilation parameters

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

3. Compile and install PHP

Execute the make command to compile:

make

Then execute the make install command to install:

make install

4. Configure PHP and Nginx cooperation

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;
}

5. Restart Nginx and PHP-FPM

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

Summary

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn