Nginx PHP-FPM Installation Configuration
Nginx itself can not 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 the results returned to the client.
Nginx is generally the request to send fastcgi management process processing, FASCGI management process Select the CGI subprocess processing results and return to be Nginx
This article takes php-fpm as an example to explain how to make Nginx support PHP
I. Compiling and installing PHP-FPM
What is PHP-FPM
PHP-FPM is a PHP fastcgi manager that is only used in 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 the PHP package. It must be patch to your PHP source code and can be used only after compiling and installing PHP.
The new version of PHP has been integrated PHP-FPM, no longer a third party package, recommended use. PHP-FPM provides a better way to manage PHP processes, can effectively control memory and process, can smooth overload PHP configuration, than spawn-fcgi has more advantages, so by the official PHP included. In the./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.
Prepare before installation
Execute under CentOS
Yum-y install gcc automake autoconflibtool make
Yum-y Install gcc gcc-c++ glibc
Yum-y Install Libmcrypt-devel mhash-devellibxslt-devel \
Libjpeg libjpeg-devel libpng libpng-develfreetype freetype-devel libxml2 \
Zlib zlib-devel glibc glibc-devel glib2glib2-devel bzip2 \
ncurses ncurses-devel Curl Curl-devele2fsprogs e2fsprogs-devel \
krb5 krb5-devel libidn libidn-devel opensslopenssl-devel
Tips:
Setting up Install Process
No Package Libmcrypt-devel available.
No Package Mhash-devel available.
Source Code manual Installation Libmcrypt and Mhash
New PHP-FPM installation (recommended installation method)
Wgethttp://cn2.php.net/distributions/php-5.4.7.tar.gz
Tar zvxf php-5.4.7.tar.gz
CD php-5.4.7
./configure--prefix=/usr/local/php5.4--ENABLE-FPM--with-mcrypt=/usr/local/libmcrypt\
--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=/usr/local/mhash--enable-zip--with-pcre-regex--with-mysql--with-mysqli \
--with-gd--with-jpeg-dir
Make all Install
Both of the above can be installed PHP-FPM, after the installation of content in the/usr/local/php directory
The above completes the PHP-FPM installation.
The following is the setting for the PHP-FPM run user
cd/usr/local/php
CP etc/php-fpm.conf.defaultetc/php-fpm.conf
VI etc/php-fpm.conf
Modify
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, modify the Nginx configuration file to support PHP-FPM
After the Nginx installation is complete, modify the Nginx configuration file to nginx.conf
The server section increases the following configuration, pay attention to the red content configuration, otherwise there will be no input filespecified. Error
# Pass the PHP scripts to FastCGI serverlistening on 127.0.0.1:9000
#
Location ~ \.php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename$document_root$fastcgi_script_name;
Include Fastcgi_params;
}
Create a test PHP file
Creating PHP Files
Create the index.php file under/usr/local/nginx/html and enter the following
<?php
Echo Phpinfo ();
?>
V. Start the service
Start PHP-FPM and Nginx
/usr/local/php/sbin/php-fpm
#手动打补丁的启动方式/usr/local/php/sbin/php-fpm Start
Sudo/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 that you may encounter when you install PHP-FPM:
1. PHP Configure Error
Configure:error:XML configuration couldnot be found
Apt-get Install LIBXML2 Libxml2-dev (Ubuntu)
Yum-y Install LIBXML2 libxml2-devel (CentOS)
2. Please reinstall the BZIP2 distribution
Wgethttp://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
TAR-ZXVF bzip2-1.0.5.tar.gz
CD bzip2-1.0.5
Make
Make install
3. PHP has a row of--with-mysql=/usr in the configuration file.
When you install the prompt:
Configure:error:Cannot Find MySQL headerfiles under Yes.
The MySQL client library is notbundled anymore.
This is due to the installation of MySQL did not install MySQL header file, or the path specified incorrectly, PHP can not find the MySQL header file caused by the error prompts.
Workaround.
(1.) See if your system has a MySQL header installed
Find/-name Mysql.h
If there is. Please specify--with-mysql=/with 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 the PHP configuration option to add--WITH-MYSQL=/USR can be.
4.No input file specified.
Location ~ \.php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}
5. If the PHP configure is missing, you can install the library (Ubuntu)
sudo apt-get install make Bison Flex Gccpatch autoconf Subversion Locate
sudo apt-get install Libxml2-dev libbz2-devlibpcre3-dev libssl-dev zlib1g-dev libmcrypt-dev Libmhash-dev Libmhash2libcurl4-openssl-dev Libpq-dev libpq5 Libsyck0-dev
6. Mcrypt.h not found. Please Reinstalllibmcrypt
Apt-get Install Libmcrypt-dev
Or
Cd/usr/local/src
Wgethttp://softlayer.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
TAR-ZXVF libmcrypt-2.5.8.tar.gz
cd/usr/local/src/libmcrypt-2.5.8
./configure--prefix=/usr/local
Make
Make install
7. PHP-FPM 5.4.7 How to turn off reboot.
The PHP-FPM in PHP 5.4.7 no longer supports PHP-FPM previously available commands such as/USR/LOCAL/PHP/SBIN/PHP-FPM (Start|stop|reload), which require signal control:
The master process can understand the following signals
INT, TERM immediately terminate QUIT smooth terminate USR1 reopen log file USR2 smooth overload of all worker processes and reload configuration and binary modules
Example:
PHP-FPM off:
Kill-int ' Cat/usr/local/php/var/run/php-fpm.pid '
PHP-FPM reboot:
KILL-USR2 ' Cat/usr/local/php/var/run/php-fpm.pid '
To view the number of PHP-FPM processes:
PS aux | Grep-c PHP-FPM
8. Execute PHP under command line, prompt cannot find command
-bash:/usr/bin/php:no such file ordirectory
Vi/etc/profile
Add one line of configuration to the bottom of the file
Export Path=/usr/local/php/bin: $PATH
Save exit
Source/etc/profile