Install nginx in Ubuntu
Sudo apt-Get install nginx
After Ubuntu is installed, the file structure is roughly as follows:
All configuration files are under/etc/nginx, and each virtual host is already under/etc/nginx/sites-available.
Program file in/usr/sbin/nginx
Logs are stored in/var/log/nginx.
The Startup Script nginx has been created under/etc/init. d /.
The default virtual host directory is/var/www/nginx-default.
Start nginx
Sudo/etc/init. d/nginx start
Then you can access http: // localhost/. Everything is normal! If it cannot be accessed, do not continue. Check the cause and then continue.
Nginx default page
Configure PHP and MySQL
Install PHP and MySQL
Install PHP and MySQL:
Sudo apt-Get install php5-cli php5-cgi mysql-server php5-mysql
Install FastCGI
The/usr/bin/spawn-fcgi file is used to manage FastCGI. It originally belongs to the Lighttpd package, but after 9.10, spawn-fcgi is separated into a separate package:
Sudo apt-Get install spawn-fcgi
Configure nginx
Modify the nginx configuration file:/etc/nginx/sites-available/default modify the Host Name:
SERVER_NAME localhost;
Modify the row of index:
Index index. php index.html index.htm;
Remove the following comments to support PHP scripts:
Location ~ \. Php $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param script_filename/var/www/nginx-default $ fastcgi_script_name;
Include/etc/nginx/fastcgi_params;
}
Restart nginx:
/Etc/init. d/nginx stop
/Etc/init. d/nginx start
Start FastCGI PHP:
Spawn-fcgi-A 127.0.0.1-P 9000-C 10-u www-data-F/usr/bin/PHP-CGI
To enable PHP-CGI to boot automatically:
CD/etc/init. d
CP nginx PHP-CGI
Vim PHP-CGI
Replace nginx with PHP-CGI
And modify the corresponding part:
Daemon =/usr/bin/spawn-fcgi
Daemon_opts = "-A 127.0.0.1-P 9000-C 10-u www-data-F/usr/bin/PHP-cgi"
...
Stop)
Echo-n "Stopping $ Desc :"
Pkill-9 PHP-CGI
Echo "$ name ."
Run rcconf to set PHP-CGI to start automatically
Create and test phpinfo:
Sudo VI/var/www/nginx-default/info. php
Open http: // localhost/info. php.