Home > Article > Backend Development > Teach you step by step how to compile and install Nginx and PHP
Compiling and installing Nginx and PHP is a common way, which can achieve more flexible and customized configurations. The following will explain step by step how to compile and install Nginx and PHP. At the same time Provide specific code examples.
First, we need to prepare a server with a Linux system installed. This article uses CentOS 7 as an example for demonstration.
Step 1: Prepare the environment
Before starting the installation, we need to ensure that the server has installed some necessary software and tools, such as gcc, make, openssl-devel , pcre-devel, zlib-devel, etc. You can install it through the following command:
sudo yum install gcc make openssl-devel pcre-devel zlib-devel
Step 2: Compile and install Nginx
wget http://nginx.org/download/nginx-1.20.0.tar.gz tar -zxvf nginx-1.20.0.tar.gz cd nginx-1.20.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make make install
/usr/local/nginx/sbin/nginx
Now, you can access the server's IP address through the browser. If you see the Nginx welcome page, the installation is successful.
Step 3: Compile and install PHP
wget https://www.php.net/distributions/php-7.4.21.tar.gz tar -zxvf php-7.4.21.tar.gz cd php-7.4.21
./configure --prefix=/usr/local/php --with-curl --with-fpm --with-mysqli --with-mbstring
make make install
cp sapi/fpm/php-fpm.service /etc/systemd/system/ systemctl enable php-fpm systemctl start php-fpm
Step 4: Configure Nginx to support PHP
vim /usr/local/nginx/conf/nginx.conf
Add the following content in the server
block to Support PHP:
location ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
/usr/local/nginx/sbin/nginx -s reload
Now, you can create a php file in the Nginx Web directory and access the file, if it can be displayed normally PHP page, indicating that the installation is successful.
Through the above steps, we successfully completed the compilation and installation of Nginx and PHP, and configured them to work normally. I hope this article can help readers in need, so that everyone can have a deeper understanding and mastery of compilation and installation methods.
The above is the detailed content of Teach you step by step how to compile and install Nginx and PHP. For more information, please follow other related articles on the PHP Chinese website!