The role of PHP-FPM

Source: Internet
Author: User
Tags bz2 curl fpm install php ldap mysql client openssl php source code

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 autoconf libtool make

yum-y install gcc gcc-c++ glibc yum-y install

libmcrypt-devel Mhash-devel libxslt-devel 
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel< C3/>zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel Curl curl-devel E2FSP 
Rogs 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.gz tar zvxf php-5.4.7.tar.gz CD 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-sysvshm--enable-pcntl--enable-mbregex--with-mhash--enable-zip--with-pcre-regex-- With-mysqli--WITH-GD--with-jpeg-dir make all install 

old version manual patch PHP-FPM installation (the old version of the program is gone, everyone new version of it, here to do a show)
wget http://cn2.php. net/get/php-5.2.17.tar.gz
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
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-mysql=/usr/local/mysql
-with-mysqli=/usr/local/mysql/bin/mysql_config-with-openssl- Enable-fpm-enable-mbstring
-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 br>-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
-with-pdo-mysql
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.default etc/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

Ii. Compiling and installing Nginx

Then follow the Http://www.nginx.cn/install installation Nginx

Iii. 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 file specified. Error

# Pass the PHP scripts to FastCGI server listening 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 could not to be found

Apt-get Install LIBXML2 Libxml2-dev (Ubuntu) yum-y Install-libxml2 libxml2-devel
(CentOS)

2. Please reinstall the BZIP2 distribution

wget http://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 header files under Yes.
The MySQL client library is not bundled 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 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

Or

Cd/usr/local/src
wget http://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 or directory

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


Original: http://blog.csdn.net/lzz360/article/details/49100109

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.