Ubuntu Configuration Nginx+php+mysql Detailed _php example

Source: Internet
Author: User

1, update

Www.jb51.net

Copy Code code as follows:

sudo apt-get update

2. Installation Nginx

Copy Code code as follows:

sudo apt-get intsall nginx

After Ubuntu installation, the file structure is roughly:

* All configuration files are under/etc/nginx, and each virtual host is scheduled under/etc/nginx/sites-available www.jb51.net

* Program Files in the/usr/sbin/nginx * log in the/var/log/nginx

* and a startup script has been created under/etc/init.d/nginx

* The default virtual host directory is set to/var/www/nginx-default

The following can start Nginx to see the effect (please make sure that 80 ports are not using any other service):

Copy Code code as follows:

Sudo/etc/init.d/nginx start

#或者简单的

Copy Code code as follows:

Service Nginx Start

Then open the browser and check http://localhost/to see if the "Welcome to nginx!" is seen, indicating that the installation was successful.

Of course, basically, this piece of the child will not be a problem. If the operation is unsuccessful, you can first

Copy Code code as follows:

sudo killall apache2

Kill the Apache Process

3. Install PHP

Copy 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 php-cgi processes to prevent process crashes or inefficient single processes.

Many people on the internet have said that to use spawn-fcgi must have to install LIGHTTPD, actually not necessary, can be directly installed spawn-fcgi

Run:

Copy Code code as follows:

sudo apt-get install spawn-fcgi

5, configuration

The next is the most annoying configuration.

Configure Nginx and spawn-fcgi to run together

(1). At the end of the/etc/nginx/fastcgi_params file, add a line that you can use

 
  

Join this row:

Fastcgi_param script_filename $document _root$fastcgi_script_name;

(2). In addition, you need to find the Cgi.fix_pathinfo option in the php-cgi configuration file (this profile is located in/etc/php5/cgi/php.ini on Ubuntu), and modify it to:

Cgi.fix_pathinfo=1;

This allows the php-cgi to normally use the script_filename variable.

(3). Open/etc/nginx/sites-available/default file in

server {
listen;
server_name localhost;

Add the absolute address of the Web root directory below, using the default address of Nginx

Root/var/www/nginx-default

That is, the root and server_name siblings, which is equivalent to Apache's default directory

If this is not the case, it is easy to execute the PHP file, will prompt "no input file specified."

I've been around a lot of circles to find out. And 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 up the 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 open php file appears: No input file specified please check php.ini configuration

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 this path is correct.

Check the configuration file under/etc/nginx/sites-available, Server contains root and address instead of 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 parameter meaning is as follows

*-f Specifies the location of the executing program that invokes the FASTCGI process, depending on what PHP is installed on the system
*-a binding to address addr
*-P is bound to ports port
*-S path to a UNIX socket
*-c Specifies the number of fastcgi processes generated, default is 5 (PHP only)
*-p Specifies the PID file path of the resulting process
*-U and-g fastcgi to 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. can now be placed in the Web root of a probe or PHP file test

8, install MySQL

sudo apt-get install mysql-server mysql-client

You will be prompted to enter the root password and enter it in turn.

Start MySQL

Sudo/etc/init.d/mysql start

Test the MySQL service is normal:

Run

Mysql-uroot-p

Enter MySQL password

show databases;

If you see what's underneath

| Database |
| Information_schema |
| MySQL |

MySQL is installed correctly.

At this point, the Nginx+php+mysql under Ubuntu is complete.

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.