Table of Contents
Prerequisites
Download and Unzip
Compile and install
PHP Support
Conclusion
Home Backend Development PHP Problem How to compile NGINX and support PHP

How to compile NGINX and support PHP

Apr 12, 2023 pm 03:36 PM

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.

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

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

SCRIPT_FILENAMEThe parameter specifies the path to the PHP script.

Conclusion

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)