1. Install Nginx First
sudo apt-get install Nginx
2. Install PHP and PHP5-FPM modules
sudo apt-get install Nginx php5-fpm
Start Nginx, and Access 127.0.0.1:
/etc/init.d/nginx start
The following figure:
3, edit the configuration file
sudo vim/etc/nginx/site-available/default
Locate and edit the appropriate location as follows:
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;
}
Nginx default page directory in:/usr/share/nginx/html; you can find it in the/etc/nginx/site-available/default configuration file.
To create a index.php, type the following code:
<?php
echo "Hello world!";
>
Access this page: 127.0.0.1/index.php, if there is an error (this is the error I started after installing Nginx):
View Log file (/var/log/nginx/error.log) if similar to the following error:
Unix:/var/run/php5-fpm.sock failed (2:no such file or directory) while connecting to upstream, client:192.168.2.1, serve R:localhost, Request: "Get/index.php http/1.1", Upstream: "Fastcgi://unix:/var/run/php5-fpm.sock:"
The PHP-FPM module can be restarted:
Reboot Nginx:
/etc/init.d/nginx Restart
Access again: 127.0.0.1/index.php, normal access:
Nginx Support for PHP has been completed
Reference Address:
http://blog.csdn.net/hursing/article/details/21527159
Http://www.cnblogs.com/zdz8207/p/3765579.html