Nginx php-fpm Installation Configuration (RPM)

Source: Internet
Author: User
Tags diff ldap mcrypt php source code

Nginx itself cannot handle PHP, it is just a Web server, when the request is received, if it is a PHP request, then sent to the PHP interpreter processing, and return the results to the client.

Nginx is generally the request to send fastcgi management process processing, FASCGI management process Select the CGI sub-process processing results and return to the Nginx

This article takes php-fpm as an example to explain how to make Nginx support PHP

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

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 automake autoconf libtool Makeyum-Y Install gcc gcc-C++Glibcyum-Y Install Libmcrypt-Devel Mhash-Devel libxslt-Devel libjpeg Libjpeg-devel libpng libpng-devel FreeType Freetype-devel libxml2 libxml2-devel zlib Zlib-devel glibc glibc-devel glib2 glib2< Span class= "pun" >-devel bzip2 bzip2-devel ncurses ncurses< Span class= "pun" >-devel Curl Curl-devel e2fsprogs e2fsprogs< Span class= "pun" >-devel krb5 krb5-devel libidn Libidn-devel OpenSSL openssl-devel    

New PHP-FPM installation (recommended installation method)

wget 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 Span class= "pun" >--with-mysqli --with-gd --with -jpeg-dirmake all install    

old version manual patch PHP-FPM installation (old version of the program has gone, everyone new version of it, here to do a show)
Tar zvxf php-5.2.17.tar.gz
gzip-cd php-5.2.17-fpm-0.5.14.diff.gz | patch-d php-5.2.17-p1
CD php-5.2.17
./ Configure--prefix=/usr/local/php-with-config-file-path=/usr/local/php/etc\
- With-freetype-dir-with-jpeg-dir-with-png-dir-with-zlib-dir-with-libxml-dir=/usr-enable-xml\
-with-mhash- With-mcrypt-enable-pcntl-enable-sockets  -with-bz2-with-curl-with-curlwrappers\
-enable-mbregex-with-gd -enable-gd-native-ttf-enable-zip-enable-soap-with-iconv-enable-bcmath\
-enable-shmop-enable-sysvsem- Enable-inline-optimization-with-ldap-with-ldap-sasl-enable-pdo\
make all install

Both of these methods can be installed PHP-FPM, after the installation content in the/usr/local/php directory

The above completed the installation of PHP-FPM.

Here are the settings for the PHP-FPM running user

/usr/local/PHPCP etc/php-fpm.  Conf.  Default etc/php-fpm.  CONFVI etc/php-fpm.  conf                  

user = Www-data
Group = Www-data

If the Www-data user does not exist, add the Www-data user first
Groupadd Www-data
Useradd-g Www-data Www-data

Second, compile and install Nginx

Then follow Http:// to install Nginx

Third, modify the Nginx configuration file to support PHP-FPM

After Nginx installation is complete, modify nginx config file to nginx.conf

Where the server segment adds the following configuration, note the Red content configuration, otherwise there will be no input file specified. Error

# Pass the PHP scripts to FastCGI server listening on
Location ~ \.php$ {
root HTML;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;

Iv. Creating a test PHP file

Creating PHP Files

Create the index.php file under/usr/local/nginx/html, and enter the following:

<? php    Echo phpinfo();? >  

Five, start the service

Start PHP-FPM and Nginx

/usr/local/php/sbin/php-#手动打补丁的启动方式/usr/local/php/sbin/php-fpm start /usr/local/nginx/nginx         

PHP-FPM Close restart See end of article

VI. Browser access

Visit http://Your server ip/index.php, you can see the PHP information.

Errors you may encounter when installing PHP-FPM:

1. Error when PHP configure

Configure:error:XML configuration could not being found

Apt-get install libxml2 libxml2-Dev ( under Ubuntu)-y install libxml2 libxml2 -devel( under CentOS)              

2. Please reinstall the BZIP2 distribution

wget bzip2-1.0.  5.tar.  GZCD bzip2-1.0.  5makemake Install              

3. there is a line--with-mysql=/usr in the PHP configuration file.
When installing the prompt:
Configure:error:Cannot find MySQL header files under Yes.
Note that the MySQL client library is not bundled anymore.

This is due to the installation of MySQL when the MySQL header file is not installed, or the path is not specified correctly, PHP can not find the header file caused by the error message.
(1.) Check to see if your system has MySQL header installed
Find/-name Mysql.h
If there is. Please specify--with-mysql=/and your normal path.
If not. Take a look at the next step.
(2.) Redhat Installation
RPM-IVH mysql-devel-4.1.12-1.i386.rpm
(3.) Ubuntu Installation
Apt-get Install Libmysqlclient15-dev
(4.) The last step of PHP configuration option to add--WITH-MYSQL=/USR!

4.No input file specified.

Location ~ \.php$ {
root HTML;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;

5. If PHP Configure is missing the library, you can install the library (Ubuntu)

sudo apt-get install make Bison flex gcc patch autoconf Subversion Locate
sudo apt-get install Libxml2-dev libbz2-dev libpcre3-dev libssl-dev zlib1g-dev libmcrypt-dev libmhash-dev libmhash2 LIBCU Rl4-openssl-dev Libpq-dev libpq5 Libsyck0-dev

6. mcrypt.h not found. Please reinstall Libmcrypt

Apt-get Install Libmcrypt-dev


TAR-ZXVF libmcrypt-2.5.8.tar.gz
Make install

7. php-fpm 5.4.7 How do I turn off reboot?

PHP-FPM in PHP 5.4.7 no longer supports commands such as/USR/LOCAL/PHP/SBIN/PHP-FPM (Start|stop|reload) that php-fpm previously had, and signal control is required:

The master process can understand the following signals

INT, term immediately terminate QUIT smooth terminate USR1 reopen log file USR2 Smooth reload all worker processes and reload the configuration and binary modules


PHP-FPM off:

Kill-int ' Cat/usr/local/php/var/run/ '

PHP-FPM Restart:

KILL-USR2 ' Cat/usr/local/php/var/run/ '

To view the number of PHP-FPM processes:

PS aux | Grep-c PHP-FPM

8. Execute PHP at the command line, prompting for the command not found

-bash:/usr/bin/php:no such file or directory


Add a line of configuration at the bottom of the file
Export Path=/usr/local/php/bin: $PATH

Save exit


Nginx php-fpm Installation Configuration (RPM)

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: 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.