NGINX+PHP-FPM Environment Configuration Detailed steps

Source: Internet
Author: User
Tags fpm php source code phpinfo nginx server

NGINX+PHP-FPM Environment Configuration detailed steps

The most complete Nginx versions:http://nginx.org/download/

First, compile and install PHP-FPM

What is PHP-FPM

PHP-FPM is a PHP fastcgi manager that is only for PHP and can be downloaded in http://php-fpm.org/download.

PHP-FPM is actually a patch of PHP source code designed to integrate FASTCGI process management into a PHP package. It must be patch into your PHP source code and can be used after compiling and installing PHP.

The new version of PHP has been integrated PHP-FPM, is no longer a third-party package, recommended to use . PHP-FPM provides a better way to manage the PHP process, can effectively control memory and process, can be smooth overloaded PHP configuration, more than spawn-fcgi has more advantages, so by the official PHP included. In./configure with the –ENABLE-FPM parameter can be opened PHP-FPM, the other parameters are configured PHP, the meaning of the specific options can be viewed here.

Pre-Installation Preparation
Executed under CentOS

Yum-y install gcc gcc-c++ glibc libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freet ype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncu Rses-devel Curl Curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel OpenSSL openssl-devel

New PHP-FPM installation ( recommended installation method )

wget http://cn2.php.net/distributions/php-5.4.7.tar.gztar zvxf php-5.4.7.tar.gzcd php-5.4.7./configure--prefix=/ usr/local/php--enable-fpm--with-mcrypt--enable-mbstring--disable-pdo--with-curl--disable-debug--disable-rpath- -enable-inline-optimization--with-bz2--with-zlib--enable-sockets--enable-sysvsem--enable-sysvshm--enable-pcntl --enable-mbregex--with-mhash--enable-zip--with-pcre-regex--with-mysql--with-mysqli--with-gd--with-jpeg-dir make All install

The default installation location for PHP is already specified as/usr/local/php, and the appropriate files are then configured:

CP php.ini-development/usr/local/php/lib/php.inicp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/ PHP-FPM.CONFCP Sapi/fpm/php-fpm/usr/local/bin

Then set php.ini, using: vim/usr/local/php/lib/php.ini Open the PHP configuration file to find the Cgi.fix_pathinfo configuration item, which is annotated by default and has a value of 1, according to the official documentation, This is to prevent malicious script injection from being sent to the backend's PHP-FPM module when the file does not exist, so the entry should be stripped of the comment and set to 0

650) this.width=650; "src=" Http://images2015.cnblogs.com/blog/734555/201604/734555-20160423203125413-1833914818.png "/>

Save and exit after Setup

Also note that one place is the location of the php.ini configuration file can be set in pre-compilation configuration parameters, compile parameters can be written as:--with-config-file-path=/usr/local/php In this case, PHP will go back to the specified directory to read the php.ini configuration file, if not add the default location is the PHP installation directory of the Lib directory, can also be viewed in the phpinfo () output interface, If PHP.ini is placed in another location, PHP cannot read it, then all configuration changes are not effective, this should be noted

At this point you should create a Web user first:

Groupadd www-datauseradd-g Www-data Www-data

Then online some tutorials say let modify php-fpm.conf add the above created users and groups, at this time use vim/usr/local/etc/php-fpm.conf Open the file after the official prompt location is not found:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/734555/201604/734555-20160423203734585-1638778758. PNG "width=" 695 "height=" 157 "/>

If you add in a location at this point, then the next time you start PHP-FPM, you will report the directory can not find errors, so do not add users and groups in php-fpm.conf, this time to php-fpm.conf the last line will find the following ( If you add the--prefix option at compile time the following location will be automatically complete, the default is the following is empty, pay attention to):

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/734555/201604/734555-20160423204037507-1765899356. PNG "width=" 424 "height=" 158 "/>

All the Conf configuration files in the PHP-FPM.D directory are introduced here, but none needs to be modified to our actual directory:/usr/local

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/734555/201604/734555-20160423204220632-121130420. PNG "width=" 410 "height=" 117 "/>

By default, etc/php-fpm.d/has a configuration user file named Www.conf.defalut, which executes the following command to copy a new file and open:

cp/usr/local/etc/php-fpm.d/www.conf.default/usr/local/etc/php-fpm.d/www.confvim/usr/local/etc/php-fpm.d/ Www.conf

The default user and group settings are nobody, which is changed to Www-data

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/734555/201604/734555-20160423204724257-883955154. PNG "width=" 382 "height="/>

After the modification is complete, save and exit, and then execute the following command to start the PHP-FPM service:

/usr/local/bin/php-fpm

After the boot is complete, the PHP-FPM service uses port 9000 by default, using netstat-tln | grep 9000 can view port usage:

650) this.width=650; "src=" Http://images2015.cnblogs.com/blog/734555/201604/734555-20160423205017882-796724459.png "/>

9000 port normal use, indicating PHP-FPM service started successfully

Then execute vim/usr/local/nginx/nginx.conf edit nginx configuration file, the specific path according to the actual nginx.conf configuration file location editing, the following main changes in Nginx server {} configuration block content , modify the location block, append index.php let Nginx server default support index.php home page:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/734555/201604/734555-20160423205354601-1507906007. PNG "width=" 434 "height="/>

Then configure the. PHP request to be routed to the backend PHP-FPM module, where the PHP configuration block is annotated by default, and the comment is removed and modified to the following:

650) this.width=650; "src=" Http://images2015.cnblogs.com/blog/734555/201604/734555-20160423205619741-893234264.png "/>

Many of these are default, root is the configuration of PHP program placement root directory, the main modification is fastcgi_param in the/scripts for $document_root

Modify the above, go back to the first line nginx.conf, the default is #user nobody; This is to remove the comment to user www-data, or user Www-data Www-data, which indicates that the permissions of the Nginx server are Www-data

Modify these save and exit, and then restart Nginx:

/usr/local/nginx/nginx-s Stop/usr/local/nginx/nginx

Next edit a test PHP program, under Nginx under the HTML directory to create the info. php file, print the PHP configuration:

<?php phpinfo ();? >

Then open the browser to enter the corresponding address to access, see the output page, stating that Nginx and PHP are configured successfully:

650) this.width=650; "Src=" http://img.blog.csdn.net/20170407172759461?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmdy3odg0nw==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Center "/>


This article from "Rookie also want to fly" blog, please be sure to keep this source http://xiumin.blog.51cto.com/6205237/1929864

NGINX+PHP-FPM Environment Configuration Detailed steps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.