Configuring Nginx Support PHP

Source: Internet
Author: User

Nginx itself does not support PHP. If you need to use PHP, you need to install PHP parsing services, such as PHP-FPM, or spawn-fcgi. From the ease of configuration on Ubuntu, this time using the PHP-FPM implementation.

Installing PHP and PHP-FPM

Installation method, slightly ...

Because it can be installed directly with the package manager.

The service needs to be started after installation.

modifying Nginx configuration Files

To modify the configuration file/etc/nginx/sites-available/default, first let the default page have PHP files:

index index.php index.html index.htm;

Then turn on PHP support and find the "location ~. php" section to modify the comments:

location ~ \.php$ {fastcgi_split_path_info ^(.+\.php)(/.+)$;# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini# With php5-cgi alone:#fastcgi_pass 127.0.0.1:9000;# With php5-fpm:fastcgi_pass unix:/var/run/php5-fpm.sock;fastcgi_index index.php;include fastcgi_params;}

"Fastcgi_pass 127.0.0.1:9000;" It is related to spawn-fcgi, so it should be commented. The Nginx service needs to be restarted after modifying the configuration file.

Principle

According to the Internet: "Nginx itself can not handle PHP, it is a Web server, when the request is received, if it is a PHP request, then sent to the PHP interpreter processing, and return the results to the client." Nginx is generally the request to send fastcgi management process processing, FASCGI management process Select CGI subprocess processing results and return to Nginx ". In other words, Nginx will process the request to PHP5-FPM, and then receive processing return results.

Reference

Http://www.nginx.cn/231.html

Original link Address: http://pangyi.github.io/blog/20150118/pei-zhi-nginxzhi-chi-php/
Written by Pangyi posted at Http://pangyi.github.io

Configuring Nginx Support 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.