How to compile NGINX and support PHP

WBOY
Release: 2023-05-18 19:50:44
forward
1195 people have browsed it

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

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

Unzip the downloaded file:

$ tar -zxvf nginx-1.19.2.tar.gz
Copy after login

Enter the decompression directory:

$ cd nginx-1.19.2
Copy after login

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

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

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!

Related labels:
source:yisu.com
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!