1024programmer Nginx How to install and configure Nginx and PHP-fpm

How to install and configure Nginx and PHP-fpm

nginx itself cannot handle PHP, it is just a web server, when a request is received, if it is a PHP request, it will be sent to the PHP interpreter for processing, and the result will be returned to the client.

Nginx generally sends the request to the fastcgi management process for processing, and the fascgi management process selects the cgi sub-process processing result and returns it to be processed by nginx

This article takes php-fpm as an example to introduce how to make nginx support PHP

1. Compile and install php-fpm

What is PHP-FPM

PHP-FPM is a PHP FastCGI manager for PHP only, available at
http://php-fpm.org/download to download.

PHP-FPM is actually a patch of the PHP source code, aiming to integrate FastCGI process management into the PHP package. It must be patched into your PHP source code, and it can be used after compiling and installing PHP.

The new version of PHP has integrated php-fpm, it is no longer a third-party package, it is recommended to use. PHP-FPM provides a better PHP process management method, which can effectively control memory and process, and can smoothly reload PHP configuration. It has more advantages than spawn-fcgi, so it is officially included by PHP. When ./configure takes
The ?enable-fpm parameter can enable PHP-FPM.

New version of 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-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

Old version manually patched php-fpm installation

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

Both of the above methods can install php-fpm, and the content will be placed in the /usr/local/php directory after installation.

/

cd /usr/local/php

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

Revise

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 http://www.nginx.cn/install

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

After the nginx installation is complete, modify the nginx configuration file to nginx.conf

Add the following configuration to the server section, pay attention to the red content configuration, otherwise No input file specified. error will appear

# 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;
}

Fourth, create a test php file

create php file

Create an index.php file under /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 start method /usr/local/php/sbin/php-fpm start)

sudo /usr/local/nginx/nginx

6. Browser access

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

/

Errors that may be encountered when installing php-fpm:

1. An error occurred during phpconfigure

configure: error: XML configuration could 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 –with-mysql=/usr in the configuration file of php. Prompt during installation:
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore.

This is due toThe mysql header file was not installed when installing mysql, or the path was specified incorrectly, and the error message caused by php not finding the mysql header file.
Solution.
(1.) Check if mysql header is installed in your system
find / -name mysql.h
If there is. Please specify –with-mysql=/ followed by your normal path.
if there is not. Please see 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.) In the last step, add –with-mysql=/usr to the configuration option of php!
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 library is missing during php configure, you can 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

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/how-to-install-and-configure-nginx-and-php-fpm/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索