Nginxphp-fpm configuration

Source: Internet
Author: User
Tags mcrypt xslt
Nginx itself cannot process PHP. it is only a web server. after receiving the request, if it is a php request, it is sent to the php interpreter for processing and the result is returned to the client. Nginx generally sends requests to the fastcgi management process. The fascgi management process selects the cgi sub-process to process the results and returns the results... nginx itself cannot process PHP. it is only a web server. after receiving the request, if it is a php request, it is sent to the php interpreter for processing and the result is returned to the client.

Nginx generally sends requests to the fastcgi management process. The fascgi management process selects the cgi sub-process to process the results and returns the results

This document uses php-fpm as an example to describe how to enable nginx to support PHP

I. Compile and install php-fpm

What is PHP-FPM

PHP-FPM is a PHP FastCGI manager that is only used for PHP and can be downloaded at 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. You must patch it to your PHP source code before using it after compiling and installing PHP.

The new version of PHP has already integrated php-fpm and is no longer a third-party package. we recommend that you use. PHP-FPM provides a better way of PHP process management, can effectively control the memory and process, can smoothly load PHP configuration, than spawn-fcgi has more, so PHP officially included. You can enable PHP-fpm with The-enable-FPM parameter in./configure.

New version of php-fpm installation (recommended)

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-fastcgi -- enable-fpm -- with-mcrypt -- with-zlib -- enable-mbstring -- disable-pdo -- with-curl -- disable-debug -- enable-pic -- disable-rpath -- enable-inline-optimization -- with-bz2 -- with-xml -- with-zlib -- enable-sockets -- enable-sysvsem -- enable-sysvshm -- enable-pcntl -- enable-mbregex -- with-mhash -- enable-xslt -- enable-memcache -- enable-zip -- with-pcre-regex -- with-mysql

Make all install

Install php-fpm manually in the old version

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 -- enable-fastcgi -- enable-fpm -- with-mcrypt -- with-zlib -- enable-mbstring -- disable-pdo -- with-curl -- disable-debug -- enable-pic -- disable-rpath -- enable-inline-optimization -- with-bz2 -- with-xml -- with-zlib -- enable-sockets -- enable-sysvsem -- enable-sysvshm -- enable-pcntl -- enable-mbregex -- with-mhash -- enable-xslt -- enable-memcache -- enable-zip -- with-pcre-regex -- with-mysql

Make all install

 

You can install php-fpm in either of the preceding methods. after installation, the content is stored in the/usr/local/php directory.

Cd/usr/local/php

Cp etc/php-fpm.conf.default etc/php-fpm.conf

Modify

Vi etc/php-fpm.conf.default etc/php-fpm.conf

User = www-data
Group = www-data

 

2. Compile and install nginx

Then install nginx according to the http://www.nginx.cn/install

 

3. modify the nginx configuration file to support php-fpm

After nginx is installed, change the nginx configuration file to nginx. conf.

The following configuration is added to the server segment. pay attention to the configuration in red; otherwise, No input file specified will occur.

# Pass the PHP scripts to FastCGI server listening on Fig: 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;
}

 

4. create a PHP test file

Create a php file

Create the index. php file in/usr/local/nginx/html and enter the following content:

 

5. start the service

Start php-fpm and nginx

/Usr/local/php/sbin/php-fpm (manual patching startup method/usr/local/php/sbin/php-fpm start)

Sudo/usr/local/nginx

 

6. browser access

Access http: // your server ip address/index. php, you can see the php information.

 

Possible errors when installing php-fpm:

1. phpconfigure error

Configure: error: XML configuration cocould not be found
Apt-get install libxml2 libxml2-dev (under ubuntu)
Yum-y install libxml2 libxml2-devel (under 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. there is a line in the php configuration file -- with-mysql =/usr. Prompt during installation:
Configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore.

This is because the mysql header file is not installed during mysql installation, or the path is incorrectly specified, and php cannot find the mysql header file.
Solution.
(1) Check whether your system has installed the mysql header.
Find/-name mysql. h
If yes. Specify -- with-mysql =/and your normal path.
If not. Please refer to the next step.
(2) redhat installation
Rpm-ivh MySQL-devel-4.1.12-1.i386.rpm
(3) Install ubuntu
Apt-get install libmysqlclient15-dev
(4.) add -- with-mysql =/usr to the configuration option of php in the last step!
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 Library is missing, install the library first (under 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 libcurl4-openssl-dev libpq-dev libpq5 libsyck0-dev

Related Article

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.