Ubuntu+nginx+php+mysql Installation Configuration Method command

Source: Internet
Author: User
Tags fpm php source code

1. Update Ubuntu system First

Update command

sudo apt-get update

sudo apt-get upgrade

2. Updating and installing update and install

sudo apt-get update

sudo apt-get install Nginx

3, start Nginx

Sudo/etc/init.d/nginx start

4, check version

Nginx-v

5. Configure Php+mysql

sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql

6. Installation fastcgi

sudo apt-get install spawn-fcgi

7. Configure Nginx

A, modify the Nginx profile:/etc/nginx/sites-available/default Modify host Name

server_name localhost;

B, modify the row of index, add index.php

Index index.php index.html index.htm;

C, remove the comments in the following section to support PHP scripts:

Location ~ php$ {include/etc/nginx/fastcgi_params; #需放在第一行, otherwise there will be error fastcgi_pass 127.0.0.1:9000;    Fastcgi_index index.php; Fastcgi_param Script_filename/var/www/nginx-default$fastcgi_script_name; }

8. Reboot Nginx

/etc/init.d/nginx stop

/etc/init.d/nginx start

9, start fastcgi PHP

Spawn-fcgi-a 127.0.0.1-p 9000-c 10-u www-data-f/usr/bin/php-cgi

10, Nginx Tip 502 Error

Nginx 502 Bad Gateway is not started, the start command is:

Spawn-fcgi-a 127.0.0.1-p 9000-c 10-u www-data-f/usr/bin/php-cgi

11, set the boot from start

Ubuntu will execute the script in the/etc/rc.local file after boot

So we can add the startup script directly to 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.

12. 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 changed to your site root directory, is generally changed to this.

The server field has the same root directory as the site root directory

13, PHP restart

Because the spawn-fcgi is installed, you have to kill the PHP process before you restart PHP
To view the PHP process: Ps-ef | grep php
xcar@xcar:/usr/bin$ ps-ef|grep PHP
Xcar 24539 1661 0 17:35? 00:00:00/usr/bin/php-cgi
Xcar 24540 24539 0 17:35? 00:00:00/usr/bin/php-cgi
Xcar 24541 24539 0 17:35? 00:00:00/usr/bin/php-cgi
Xcar 24542 24539 0 17:35? 00:00:00/usr/bin/php-cgi
Xcar 24543 24539 0 17:35? 00:00:00/usr/bin/php-cgi
Xcar 24544 24539 0 17:35? 00:00:00/usr/bin/php-cgi
Xcar 24659 15273 0 17:39 pts/2 00:00:00 grep–color=auto php
Spawn reboot:
Spawn-fcgi-a 127.0.0.1-p 9000-c 5-u www-data-g www-data-f
The parameter meaning is as follows:
-f Specifies the location of the executing program that invokes the FASTCGI process, based on the conditions of the PHP installed on the system
-a bind to address addr
-P is bound to ports port
-S path to a UNIX socket
-c Specifies the number of fastcgi processes generated, default 5 (PHP only)
-p Specifies the PID file path of the resulting process
-U and-G FastCGI use what identity (-u user-G user group) to run, Ubuntu can use Www-data, other according to the situation configuration, such as nobody, Apache, etc.

nginx+php (spawn-fcgi) +mysql Installation Understanding

What is CGI:
the CGI full name is the "Public Gateway Interface" (Common Gateway Interface), a tool that HTTP servers "talk" to programs on your or other machines, and their programs must run on a network server.
CGI can be written in any language, as long as the language has standard input, output, and environment variables. such as PHP,PERL,TCL and so on.
What is fastcgi:
FastCGI is like a resident (long-live) CGI, which can be executed all the time, and it won't take a while to fork once (this is CGI's most criticized Fork-and-execute model). It also supports distributed operations, where the FastCGI program can execute on a host other than the Web server and accept requests from other Web servers.
The FastCGI is a language-independent, scalable, CGI-open extension that primarily acts to keep the CGI interpreter process in memory and thus achieve higher performance. As we all know, the repeated loading of CGI interpreters is the main reason for the low performance of CGI, and can provide good performance, scalability, fail-over characteristics, and so on if the CGI interpreter remains in memory and accepts the FASTCGI process Manager schedule.

FastCGI's working principle:
1. Load fastcgi process Manager at Web server startup (IIS ISAPI or Apache Module)
2, the FastCGI process manager itself initializes, initiates multiple CGI interpreter processes (visible multiple php-cgi) and waits for a connection from the Web server.
3. When a client request arrives at the Web server, the FastCGI process manager selects and connects to a CGI interpreter. The WEB server sends CGI environment variables and standard input to the fastcgi subprocess php-cgi.
4. The FastCGI child process completes processing and returns standard output and error information from the same connection to the Web Server. When the fastcgi child process closes the connection, the request is processed.  The FastCGI process then waits and processes the next connection from the FastCGI process Manager (running in Web server). In the CGI mode, php-cgi quits here.
What is php-cgi:
PHP-CGI is the fastcgi Manager with PHP.
Start php-cgi, using the following command:
#php-cgi-b 127.0.0.1:9000
Lack of php-cgi:
1, php-cgi change php.ini configuration needs to restart php-cgi to make the new Php-ini effective, can not smooth restart
2, directly kill the php-cgi process, PHP can not run. (PHP-FPM and spawn-fcgi do not have this problem, the daemon will smoothly regenerate new child processes.) )
What is php-fpm:
PHP-FPM is a PHP fastcgi manager that is only used in PHP and can be downloaded in http://php-fpm.org/download.
PHP-FPM is actually a patch of PHP source code, designed to integrate FASTCGI process management into the PHP package. It must be patch to your PHP source code and can be used only after compiling and installing PHP. Now we can download the new PHP 5.3.2 source tree to directly integrate the PHP-FPM branch, it is said that the next version will be merged into the main branch of PHP. Relative spawn-fcgi, php-fpm in the CPU and memory control is more than a chip, and the former is very easy to crash, must be monitored with crontab, and php-fpm do not have this annoyance.
php-fpm off:
Kill-sigint ' Cat/usr/local/php/var/run/php-fpm.pid '
php-fpm reboot:
KILL-SIGUSR2 ' Cat/usr/local/php/var/run/php-fpm.pid '
What is spawn-fcgi:
SPAWN-FCGI is a common fastcgi Management Server, it is a part of the LIGHTTPD, many people use LIGHTTPD spawn-fcgi mode of management work, but there are a lot of shortcomings. and PHP-FPM to alleviate some of the problems, but PHP-FPM has a drawback is to recompile, this for some already running environment may have a small risk (refer), in the PHP 5.3.3 can directly use PHP-FPM.
SPAWN-FCGI has now become a single project, more stable, but also to many Web site configuration to bring convenience. There are already a number of sites to match it with Nginx to solve dynamic Web pages.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.