NGINX is a high-performance web server, as well as acting as a reverse proxy and load balancer. Compared with other servers, NGINX takes up less memory resources and keeps the system load low. It has always been favored by many people.
Although NGINX itself supports Serving static content, it does not have a built-in PHP interpreter and requires additional installation to support PHP.
This article will show you how to compile NGINX and support PHP.
Before starting the installation, please make sure that the gcc, make and zlib-devel packages have been installed on your system. These packages can be installed with the following command:
$ sudo yum install gcc make zlib-devel
First, you need to download the NGINX source code. You can download the latest version from the official website.
$ wget https://nginx.org/download/nginx-1.19.2.tar.gz
Unzip the downloaded file:
$ tar -zxvf nginx-1.19.2.tar.gz
Enter the decompression directory:
$ cd nginx-1.19.2
To compile NGINX and support PHP, you need to compile Add --with-http_stub_status_module
and --with-http_realip_module
parameters when using NGINX.
The following are the compilation commands:
$ ./configure --prefix=/usr/local/nginx \ --with-http_stub_status_module \ --with-http_realip_module \ --with-http_ssl_module \ --add-module=/usr/local/src/ngx_cache_purge \ --add-module=/usr/local/src/headers-more-nginx-module \ --add-module=/usr/local/src/ngx_http_upstream_session_sticky_module \ --add-module=/usr/local/src/encrypted-session-nginx-module \ --add-module=/usr/local/src/nginx-module-vts $ make && sudo make install
The above command will cause NGINX to be packaged with the real-time IP module and support SSL via the --with-http_ssl_module parameter. In addition, some third-party modules have been added, such as ngx_cache_purge, headers-more-nginx-module, ngx_http_upstream_session_sticky_module, encrypted-session-nginx-module and nginx-module-vts, etc.
To support PHP in NGINX, make sure FPM is enabled when installing PHP. FPM is the abbreviation of FastCGI Process Manager, which interconnects PHP and NGINX.
Next, add the following to NGINX’s configuration file to enable PHP support.
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
SCRIPT_FILENAME
The parameter specifies the path to the PHP script.
Now you can use the high performance of NGINX with the addition of PHP, and the combination will make your web applications faster and more scalable.
In this process, you learned how to compile NGINX to support PHP. Adding PHP to NGINX can take your web application's performance to the next level.
The above is the detailed content of How to compile NGINX and support PHP. For more information, please follow other related articles on the PHP Chinese website!