1. Update Ubuntu system First
Update command
sudo apt-get update
sudo apt-get upgrade
- 2
Add Ubuntu nginx Update source image
cd/etc/apt/
sudo cp sources.list Sources.list_bak
Add the following code to the Sources.list file
Deb Http://nginx.org/packages/ubuntu/precise Nginx
DEB-SRC http://nginx.org/packages/ubuntu/precise Nginx
Use
sudo vi sources.list
If prompted: w:gpg error:http://nginx.org precise release:the following signatures couldn ' t be verified because the public key is not Available:no_pubkey abf5bd827bd9bf62 due to official distrust of the source
Workaround: sudo apt-key adv--keyserver keyserver.ubuntu.com--recv-keys abf5bd827bd9bf62
- 3
3. Updating and installing update and install
sudo apt-get update
sudo apt-get install Nginx
- 4
4. Start Nginx
Sudo/etc/init.d/nginx start
- 5
5. Check version
Nginx-v
- 6
6, Configuration Php+mysql
sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql
- 7
7, installation fastcgi
sudo apt-get install spawn-fcgi
- 8
8. Configure Nginx
8.1, modify the Nginx configuration file:/etc/nginx/sites-available/default Modify host Name
server_name localhost;
8.2, modify the index row, add index.php
Index index.php index.html index.htm;
8.3. Uncomment the following section to support PHP scripts:
Location ~. php$ {
Include/etc/nginx/fastcgi_params; #需放在第一行, or it will go wrongFastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/var/www/nginx-default$fastcgi_script_name;
}
- 9
9. Re-start Nginx
/etc/init.d/nginx stop
/etc/init.d/nginx start
- 10
10. Start fastcgi PHP
Spawn-fcgi-a 127.0.0.1-p 9000-c 10-u www-data-f/usr/bin/php-cgi
- 11
11, Nginx prompt 502 error
Nginx 502 Bad Gateway does not start, the startup command is:
Spawn-fcgi-a 127.0.0.1-p 9000-c 10-u www-data-f/usr/bin/php-cgi
- 12
12. Set Boot from boot
Ubuntu will execute scripts in the/etc/rc.local file after booting
So we can add the startup script directly in the/etc/rc.local.
Spawn-fcgi-a 127.0.0.1-p 9000-c 10-u www-data-f/usr/bin/php-cgi Add to statement: Exit 0
Just ahead.
- 13
13, no input file specified error
sudo vi/etc/nginx/sites-available/default
Where this field
Location ~. php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/var/www/nginx-default$fastcgi_script_name;
Include Fastcgi_params;
}
Attention
Fastcgi_param Script_filename/var/www/nginx-default$fastcgi_script_name;
/var/www/nginx-default change to your Web site root directory, is usually changed to this.
The root directory and the Web site root directory are consistent under the server field
Configuring Nginx+php+mysql+phpmyadmin on Ubuntu