What is Nginx1.4.x in Unix? This document includes instructions and tips for installing and configuring PHP for the Nginx1.4.xHTTP server using a PHP-FPM. This Guide assumes that you have successfully built Nginx from the source code, and its binary files and configuration files are both located in usrlocalnginx. If you want to obtain Nginx in other ways, refer?
Nginx 1.4.x in Unix? This document includes instructions and tips for installing and configuring PHP for the Nginx 1.4.x HTTP server with a PHP-FPM. This Guide assumes that you have successfully built Nginx from the source code, and its binary files and configuration files are located in/usr/local/nginx. If you want to obtain Nginx in other ways, refer?
Nginx 1.4.x in Unix?
This document includes instructions and tips for installing and configuring PHP for the Nginx 1.4.x HTTP server with a PHP-FPM.
This Guide assumes that you have successfully built Nginx from the source code, and its binary files and configuration files are both located in/Usr/local/nginx. If you want to obtain Nginx in other ways, refer? Nginx Wiki is installed in accordance with this document.
This document only contains the basic configuration of the Nginx server. It provides the processing capability of the PHP application through port 80. If you require installation configuration guidance beyond the scope of this document, we recommend that you read the Nginx and PHP-FPM documentation.
Note that this document uses 'x' to indicate the version number. Replace 'X' with the corresponding version number based on the actual situation.
How can I access Nginx Wiki? Install Nginx on your system.
Obtain and decompress the PHP source code:
tar zxf php-x.x.x
Configure and build PHP. In this step, you can use many options to customize PHP, such as enabling some extensions. Run the./configure -- help Command to obtain the complete list of available options. In this example, we only perform simple configuration that contains the PHP-FPM and MySQL support.
cd ../php-x.x.x./configure --enable-fpm --with-mysqlmakesudo make install
Create a configuration file and copy it to the correct location.
cp php.ini-development /usr/local/php/php.inicp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.confcp sapi/fpm/php-fpm /usr/local/bin
Note that, if the file does not exist, Nginx is prevented from sending requests to the backend PHP-FPM module to avoid malicious script injection attacks.
Set the configuration item cgi. fix_pathinfo in the php. ini file0.
Open php. ini:
vim /usr/local/php/php.ini
GoCgi. fix_pathinfo =And modify it as follows:
cgi.fix_pathinfo=0
Before starting the service, you need to modify the php-fpm.conf configuration file to ensure that the php-fpm module runs as the www-data user and www-data user group.
vim /usr/local/etc/php-fpm.conf
Find and modify the following content:
; Unix user/group of processes; Note: The user is mandatory. If the group is not set, the default user's group; will be used.user = www-datagroup = www-data
Then start the php-fpm service:
/usr/local/bin/php-fpm
This document does not cover further configuration of php-fpm. For more information, see the relevant documentation.
Configure Nginx to support PHP applications:
vim /usr/local/nginx/conf/nginx.conf
Modify the default location block to support the. php file:
location / { root html; index index.php index.html index.htm;}
Next configure to ensure that requests to the. php file will be sent to the back-end PHP-FPM module, uncomment the default PHP configuration block, and modify it to the following:
location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name;}
Restart Nginx.
sudo /usr/local/nginx/sbin/nginx -s stopsudo /usr/local/nginx/sbin/nginx
Create a test file.
rm /usr/local/nginx/html/index.htmlecho "
" >> /usr/local/nginx/html/index.php
Open the browser and access http: // localhost. phpinfo () is displayed ().
Through the configuration above, the Nginx server can now useSAPIThe module supports PHP applications. Run the command in the corresponding source code directory../Configure -- helpFor more configuration options.