Ubuntu10.10Nginx + PHP + PHP-FPM + MySQL simple construction implementation

Source: Internet
Author: User
First, we need to install MySQL. The installation in Ubuntu is very simple. You just need to run the following command to install the MYSQL server: sudoapt-getinstallmysql-server after installing and playing with the MySQL server, we need to install Nginx, it is best to use the official PPA source to install the latest: You can open the https://launchpad.net /~ Nginx/+ archive/development, and refer to its description

First, we need to install MySQL. The installation in Ubuntu is very simple. You just need to run the following command to install the MYSQL server:

Sudo apt-get install mysql-server

After installing and playing with the MySQL server, we need to install Nginx. It is best to use the official PPA source for the latest installation:

You can openHttps://launchpad.net /~ Nginx/+ archive/development, And refer to its description,

Add the following source to the Ubuntu source. d file:

Sudo gedit/etc/apt/sources. list

To open the source file and add the following address:

deb http://ppa.launchpad.net/nginx/development/Ubuntu maverick main

deb-src http://ppa.launchpad.net/nginx/development/Ubuntu maverick main

Then add the key in the command line,
sudo apt-key adv --keyserver keyserver.Ubuntu.com --recv-keys C300EE9

When using this command, you will find that:

Gpg: "C300EE9" is not a user sign: Skip,

This is because the hpk server does not recognize this KEY. You need to obtain it from its server again. Run the following command:

Gpg -- keyserver subkeys.pgp.net -- recv-keys DA360C64005E0276

Available information:

Gpg: The/home/jankey/. gnupg directory has been created'

.......

OK, so that we can get a KEY: 005E0276

Then run the following command:

sudo apt-key adv --keyserver keyserver.Ubuntu.com --recv-keys 005E0276

Then we can install Nginx:

Run the following command:

Sudo apt-get install nginx

After installation, install phpy + php-fpm and other required modules. Run the following command:

Sudo apt-get install php5-cgi php5-mysql php5-fpm php5-curl php5-gd php5-idn php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode

The above installation is successful,

The following is a simple configuration:

First configure the php. ini file:

Of course, if you see that the installation of the php5-fpm is not successful, Please create the www file Under var, and then use the command:

Sudo apt-get install php5-fpm

To install,

If all of the above are OK, let's open the file now:

Sudo gedit/etc/php5/fpm/php. ini

Then modify: # cgi, fix_pathinfo = 1 to cgi. fix_pathinfo = 0.

Next, modify:

Sudo gedit/etc/nginx/sites-available/default

# You may add here your
# Server {
#...
#}
# Statements for each of your virtual hosts

Server {

Listen 80; # listen for ipv4
Listen [:]: 80 default ipv6only = on; # listen for ipv6

Server_name localhost;
Root/var/www;
Access_log/var/log/nginx/localhost. access. log;

# Access_log/var/www/log/xxx-access.log;
# Error_log/var/www/logs/xxx-error.log;

Location /{
Index. php index.html index.htm;
}

Location/doc {
Root/usr/share;
Autoindex on;
Allow 127.0.0.1;
Deny all;
}

Location/images {
Root/usr/share;
Autoindex on;
}

# Error_page 404/404 .html;

# Redirect server error pages to the static page/50x.html
#
# Error_page 500 502 503 504/50 x.html;
# Location =/50x.html {
# Root/var/www/nginx-default;
#}

# Proxy the PHP scripts to Apache listening on 127.0.0.1: 80
#
# Location ~ \. Php $ {
# Proxy_pass http: // 127.0.0.1;
#}

# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ \. Php $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name;
Include fastcgi_params;
}

# Deny access to. htaccess files, if Apache's document root
# Concurs with nginx's one
#
Location ~ /\. Ht {
Deny all;
}
}


# Another virtual host using mix of IP-, name-, and port-based configuration
#
# Server {
# Listen 8000;
# Listen somename: 8080;
# Server_name somename alias another. alias;

# Location /{
# Root html;
# Index index.html index.htm;
#}
#}


# HTTPS server
#
# Server {
# Listen 443;
# Server_name localhost;

# Ssl on;
# Ssl_certificate cert. pem;
# Ssl_certificate_key cert. key;

# Ssl_session_timeout 5 m;

# Ssl_protocols SSLv3 TLSv1;
# Ssl_ciphers ALL :! ADH :! EXPORT56: RC4 + RSA: + HIGH: + MEDIUM: + LOW: + SSLv3: + EXP;
# Ssl_prefer_server_ciphers on;

# Location /{
# Root html;
# Index index.html index.htm;
#}
#}


After modifying the preceding settings, You need to modify the settings as follows:

Add sudo gedit/etc/nginx/fastcgi_params to it:


Fastcgi_param QUERY_STRING $ query_string;
Fastcgi_param REQUEST_METHOD $ request_method;
Fastcgi_param CONTENT_TYPE $ content_type;
Fastcgi_param CONTENT_LENGTH $ content_length;

Fastcgi_param SCRIPT_NAME $ fastcgi_script_name;
Fastcgi_param REQUEST_URI $ request_uri;
Fastcgi_param DOCUMENT_URI $ document_uri;
Fastcgi_param DOCUMENT_ROOT $ document_root;
Fastcgi_param SERVER_PROTOCOL $ server_protocol;

Fastcgi_param GATEWAY_INTERFACE CGI/1.1;
Fastcgi_param SERVER_SOFTWARE nginx/$ nginx_version;

Fastcgi_param REMOTE_ADDR $ remote_addr;
Fastcgi_param REMOTE_PORT $ remote_port;
Fastcgi_param SERVER_ADDR $ server_addr;
Fastcgi_param SERVER_PORT $ server_port;
Fastcgi_param SERVER_NAME $ server_name;

Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Fastcgi_param PATH_INFO $ fastcgi_script_name;
Fastcgi_connect_timeout 60;
Fastcgi_send_timeout 180;
Fastcgi_read_timeout 180;
Fastcgi_buffer_size 128 k;
Fastcgi_buffers' 4 256 k;
Fastcgi_busy_buffers_size 256 k;
Fastcgi_temp_file_write_size 256 k;
Fastcgi_intercept_errors on;

# PHP only, required if PHP was built with -- enable-force-cgi-redirect
Fastcgi_param REDIRECT_STATUS 200;

After the preceding steps are completed, you can use the following command:

Sudo... the file cp to be modified./back up the file

In this way, if an error occurs after you modify a file, you can refer to the original file after the backup for restoration. This is a habit, please note

Next we need to restart nginx and php-fpm, and use the following command:

Sudo/etc/init. d/nginx restart

Sudo/etc/init. d/php5-fpm reload

This completely completes the purpose we want to achieve today. Check whether it has been successfully set up. Create an index. php file under/var/www.

Related Article

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.