Analysis of the compilation and installation methods of Nginx and PHP

PHPz
Release: 2024-02-27 18:10:02
Original
1129 people have browsed it

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
Copy after login

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
Copy after login

3. Compile and install Nginx

Execute the make command to compile:

make
Copy after login
Copy after login

Then execute the make install command to install:

make install
Copy after login
Copy after login

4. Start the Nginx service

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

/usr/local/nginx/sbin/nginx
Copy after login

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
Copy after login

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
Copy after login

3. Compile and install PHP

Execute the make command to compile:

make
Copy after login
Copy after login

Then execute the make install command to install:

make install
Copy after login
Copy after login

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;
}
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template