Nginx and PHP Compilation and Installation Guide
In the process of building the website server, Nginx serves as a high-performance web server and reverse proxy server, while PHP is a A popular server-side scripting language, the combination of the two can run dynamic websites quickly and stably. This article will introduce the compilation and installation process of Nginx and PHP in detail, and provide specific code examples so that readers can easily complete related operations when building their own website servers.
First, you need to download the latest version of the Nginx source code package from the Nginx official website. You can visit https://nginx.org/ to download the latest version.
Before compiling and installing Nginx, you need to install some dependencies to ensure that Nginx can run normally. Enter the following command in the terminal:
sudo apt-get update sudo apt-get install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev
Decompress the downloaded Nginx source code package and enter the decompressed folder. Then execute the following command to compile and install:
./configure make sudo make install
After the installation is completed, enter the following command in the terminal to start the Nginx server:
sudo nginx
Similarly, you need to download the latest version of the PHP source code package from the official PHP website. You can visit https://www.php.net/ to download the latest version.
Before compiling and installing PHP, you need to install some dependencies to ensure that PHP can run normally. Enter the following command in the terminal:
sudo apt-get install build-essential libxml2-dev libssl-dev libcurl4-openssl-dev
Decompress the downloaded PHP source code package and enter the decompressed folder. Then execute the following command to compile and install:
./configure --with-fpm --enable-mbstring --with-openssl --enable-sockets make sudo make install
After completing the installation of PHP, you need to make some configurations to ensure that Nginx can correctly parse PHP files. Edit the Nginx configuration file and add the following content:
server { listen 80; server_name your_domain.com; root /var/www/html; location ~ .php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
After the configuration is completed, execute the following command to restart Nginx and PHP-FPM:
sudo systemctl restart nginx sudo systemctl restart php-fpm
At this point, you have successfully set up a server environment for Nginx and PHP. You can enter your domain name into the browser to access the website, and if everything goes well, you should be able to see the effect of the PHP web page running normally. I hope this Nginx and PHP compilation and installation guide will be helpful to you!
The above is the detailed content of Nginx and PHP compilation and installation guide. For more information, please follow other related articles on the PHP Chinese website!