Home  >  Article  >  Operation and Maintenance  >  How to compile NGINX and support PHP

How to compile NGINX and support PHP

WBOY
WBOYforward
2023-05-18 19:50:441198browse

Prerequisites

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

Download and Unzip

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

Compile and install

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.

PHP Support

Make sure PHP is enabled when installing FPM to support PHP in NGINX. FPM is the abbreviation of FastCGI Process Manager, which enables collaboration between 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_FILENAMEThe parameter specifies the path to the PHP script.

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete