1. Update
Www.php.net
Copy the Code code as follows:
sudo apt-get update
2. Installing Nginx
Copy the Code code as follows:
sudo apt-get intsall nginx
The file structure of Ubuntu after installation is roughly:
* All configuration files are under/etc/nginx, and each virtual host is already under/etc/nginx/sites-available www.php.net
* Program Files in/usr/sbin/nginx * log in/var/log/nginx
* and already created a startup script under/etc/init.d/. Nginx
* The default virtual host directory is set to/var/www/nginx-default
Below you can start the nginx look at the effect (make sure that port 80 does not have other services in use):
Copy the Code code as follows:
Sudo/etc/init.d/nginx start
#或者简单的
Copy the Code code as follows:
Service Nginx Start
Then open the browser, see http://localhost/see if you see "Welcome to nginx!" If you see, the installation is successful.
Of course, there's no problem with this piece of cake. If the run is unsuccessful, you can first
Copy the Code code as follows:
sudo killall apache2
Kill the Apache Process
3. Install PHP
Copy the Code code as follows:
sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5- Memcache php5-mhash php5-ming Php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl
4, Installation spawn-fcgi
Why install spawn-fcgi, which is used to control the php-cgi process to prevent a process from crashing or the efficiency of a single process too low.
Many people on the web said that to use the spawn-fcgi must be installed LIGHTTPD, in fact, not necessary, can be installed directly spawn-fcgi
Run:
Copy the Code code as follows:
sudo apt-get install spawn-fcgi
5. Configuration
The next is the most frustrating configuration.
Configuring Nginx and spawn-fcgi to run together
(1). At the end of the/etc/nginx/fastcgi_params file, add a row that you can use
Join this line:
Fastcgi_param script_filename $document _root$fastcgi_script_name;
(2). Also need to be in php-cgi profile (Ubuntu on this profile is located in/etc/php5/cgi/php.ini), find the Cgi.fix_pathinfo option, modified to:
Cgi.fix_pathinfo=1;
This allows the php-cgi to use the script_filename variable normally.
(3). Open/etc/nginx/sites-available/default file on
server {listen 80;server_name localhost;
The absolute address of the Web root is added below, here is the default address of Nginx
Root/var/www/nginx-default
That is, the root and server_name peers, which is equivalent to the Apache default directory
If this is not the case, it is easy to execute PHP files when you will be prompted "no input file specified".
I've been around a great circle to find out. Then modify
#location ~. php$ {
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#fastcgi_param Script_filename/scripts$fastcgi_script_name;
#includefastcgi_params;
#}
Modified into
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; #包含fastcgi的参数文件地址
6. Start fast_cgi Process
Sudo/usr/bin/spawn-fcgi-a 127.0.0.1-p 9000-c 5-u www-data-g www-data-f/usr/bin/php5-cgi-p/var/run/fastcgi-php.pi D
7. Set boot fastcgi process and start
sudo vi/etc/rc.local
Add next line
/usr/bin/spawn-fcgi-a 127.0.0.1-p 9000-c 5-u www-data-g www-data-f/usr/bin/php5-cgi-p/var/run/fastcgi-php.pid
If the open php file appears: No input files specified please check the configuration of php.ini
Cgi.fix_pathinfo=1
doc_root=
Also, each virtual machine according to their own different virtual machines set up a different directory, to ensure that the path is correct.
Check the configuration file under/etc/nginx/sites-available, the server contains root and address rather than root in location
Start
Fast-cgisudo/usr/bin/spawn-fcgi-a 127.0.0.1-p 9000-c 5-u www-data-g www-data-f/usr/bin/php5-cgi-p/VAR/RUN/FASTCG I-php.pid
The parameters have the following meanings
*-f Specifies the execution program location of the process that calls fastcgi, depending on the situation of PHP installed on the system
*-a bind to address addr
*-P bound to port ports
*-s bind to UNIX socket path
*-c Specifies the number of processes generated by the fastcgi, which defaults to 5 (PHP only)
*-p Specifies the PID file path of the generated process
*-U and-G fastcgi use what identity (-u user-G user group) to run, Ubuntu can use the Www-data, other configuration according to the situation, such as nobody, Apache, etc. can now be placed in the Web root directory of probe or PHP files to test it
8. Install MySQL
sudo apt-get install mysql-server mysql-client
The middle will prompt for the root user password, and then enter it.
Start MySQL
Sudo/etc/init.d/mysql start
Test that the MySQL service is working:
Run
Mysql-uroot-p
Enter MySQL password
show databases;
If you see the following content
| Database |
| Information_schema |
| MySQL |
Then MySQL is installed correctly.
At this point, the Nginx+php+mysql under Ubuntu is installed.