PHP How to use PHP-FPM to configure Nginx_PHP tutorial

WBOY
Release: 2016-07-13 10:42:23
Original
891 people have browsed it

Nginx, pronounced "Engine-X", is a web server and reverse proxy server. Nginx is well-known for its speed and ability to handle a large number of requests for resources simultaneously and for optimal utilization of resources.


PHP-FPM refers to "PHP FastCGI Process Manager". CGI is an interface standard between external applications (CGI programs) and Web servers. It is a procedure for transferring information between CGI programs and Web servers. It listens on a port just like the web server itself, and passes requests between PHP and the web server. (PS: Nice PHP Qkuan: 276167802, verification: csl)


Compared with Nginx, Apache is relatively slow when handling a large number of requests. This tutorial provides information on how to install and configure PHP-FPM Instructions for Nginx, which will help you execute PHP programs on Nginx.


1. Install Nginx


You can choose to install Nginx from source or use the management tool package that comes with the distribution.


Here we only introduce installation using the management tool package.


For example, on Ubuntu you can use apt-get to install nginx as follows:


$ sudo apt-get install nginx


Start the nginx server as follows:


$ sudo service nginx start


Then open http://localhost and see the Nginx welcome interface, which means that our installation is successful.



2. Install PHP5-FPM


Next install PHP5-FPM using the administrative toolkit.


For example, in Ubuntu you can use apt-get to install php5-fpm. As shown below:


$ sudo apt-get install php5-fpm



3. Add PHP configuration to Nginx


Next, find the /etc/nginx/sites-available/default file and add the following line:


$ sudo vi /etc/nginx/sites-available/default


server {


 listen   80;


 root /usr/share/nginx/www;


 index index.php index.html index.htm;


 server_name example.com;


 location / {


   try_files $uri $uri/ /index.html;


 }


 error_page 404 /404.html;


 error_page 500 502 503 504 /50x.html;


 location = /50x.html {


   root /usr/share/nginx/www;


 }


 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000


 location ~ \.php$ {


   try_files $uri =404;


   fastcgi_pass unix:/var/run/php5-fpm.sock;


   fastcgi_index index.php;


   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


   include fastcgi_params;


 }


}
Copy after login



4. Set listening parameters in PHP5-FPM www.conf


Next, we need to make the following changes to the php-FRPM configuration.


By default, you will see the following listening entry in the www.conf file:


$ sudo vi /etc/php5/fpm/pool.d/www.conf


listen = 127.0.0.1:9000


Replace the above monitor with the following, leaving the others intact:


$ sudo vi /etc/php5/fpm/pool.d/www.conf


listen = /var/run/php5-fpm.sock




5. Restart Nginx and PHP5-FPM


Restart php5-fpm and nginx. As shown below:


$ sudo service nginx restart



$ sudo service php5-fpm restart


Then create the index.php file in the Nginx root directory and run the test:


$ sudo vi /usr/share/nginx/www


<?php


 phpinfo( );


?>
Copy after login


Finally, open the browser and enter http://localhost/index.php to display the relevant information of PHP.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/635062.htmlTechArticleNginx, pronounced "Engine-X", is a web server and reverse proxy server. Nginx is well-known for its speed and ability to handle a large number of requests for resources simultaneously and for optimal utilization of resources. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template