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