PHP how to use PHP-FPM to Configure Nginx

Source: Internet
Author: User
Nginx reader & ldquo; Engine-X & rdquo; is a web server and reverse proxy server. Nginx is widely known for its speed, capability, and optimal use of resources when processing a large number of resources simultaneously. PHP-FPM refers to & ldquo; PHPFastCGI Process Manager & rdquo ;. CGI is an external application (CGI Nginx reads "Engine-X" and is a web server and reverse proxy server. Nginx is widely known for its speed, capability, and optimal use of resources when processing a large number of resources simultaneously.


PHP-FPM refers to the PHP FastCGI Process Manager ". CGI is the interface standard between external applications (CGI programs) and Web servers. it is the procedure for transmitting information between CGI programs and Web servers. It listens to a port like the web server itself and PHPAnd the web server. (PS: T good PHPQ button? N: 276167802, verification: csl)


Compared with Nginx, ApacheProcessing a large number of requests is relatively slow. This tutorial provides instructions on how to install and configure PHP-FPM Nginx, which will help you execute PHP programs on Nginx.


1. Install Nginx


You can choose to install Nginx from the source code or use a management toolkit with the release version.


Here we will only describe the installation using the management toolkit.


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


$ Sudo apt-get install nginx


Start the nginx server as follows:


$ Sudo service nginx start


Then open http: // localhost. The Nginx welcome page indicates that the installation is successful.



2. Install PHP5-FPM


Next install the PHP5-FPM using the administration toolkit.


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


$ 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 lines:


$ sudo vi /etc/nginx/sites-available/defaultserver { 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; }}



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 entries in the www. conf file:


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


Listen = 127.0.0.1: 9000


Replace the above listener with the following, and the rest remains 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 follows:


$ Sudo service nginx restart



$ Sudo service php5-fpm restart


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


$ sudo vi /usr/share/nginx/www
 


Finally, open the browser and enter http: // localhost/index. php. PHP.

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.