Ubuntu Nginx Installation

Source: Internet
Author: User
Tags configuration php

  1. 1. Update Ubuntu system First

    Update command

    sudo apt-get update

    sudo apt-get upgrade

  2. 2

    Add Ubuntu nginx Update source image

    cd/etc/apt/

    sudo cp sources.list Sources.list_bak

    Add the following code to the Sources.list file

    Deb Http://nginx.org/packages/ubuntu/precise Nginx

    DEB-SRC http://nginx.org/packages/ubuntu/precise Nginx

    Use

    sudo vi sources.list

    If prompted: w:gpg error:http://nginx.org precise release:the following signatures couldn ' t be verified because the public key is not Available:no_pubkey abf5bd827bd9bf62 due to official distrust of the source

    Workaround: sudo apt-key adv--keyserver keyserver.ubuntu.com--recv-keys abf5bd827bd9bf62

  3. 3

    3. Updating and installing update and install

    sudo apt-get update

    sudo apt-get install Nginx

  4. 4. Start Nginx

    Sudo/etc/init.d/nginx start

  5. 5. Check version

    Nginx-v

  6. 6, Configuration Php+mysql

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

  7. 7, installation fastcgi

    sudo apt-get install spawn-fcgi

  8. 8. Configure Nginx

    8.1, modify the Nginx configuration file:/etc/nginx/sites-available/default Modify host Name

    server_name localhost;

    8.2, modify the index row, add index.php

    Index index.php index.html index.htm;

    8.3. Uncomment the following section to support PHP scripts:

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

  9. 9. Re-start Nginx

    /etc/init.d/nginx stop

    /etc/init.d/nginx start

  10. 10. Start fastcgi PHP

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

  11. 11, Nginx prompt 502 error

    Nginx 502 Bad Gateway does not start, the startup command is:

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

  12. 12. Set Boot from boot

    Ubuntu will execute scripts in the/etc/rc.local file after booting

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

  13. 13, 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 change to your Web site root directory, is usually changed to this.

    The root directory and the Web site root directory are consistent under the server field

    Where fastcgi and php5-fpm are used to parse the PHP module, so feel free to install one of them, and then the configuration file has two location ~. php$, just cancel the bottom of the note; Install Nginx, then test to work, then install PHP CGI spawn-fcgi These modules, modify the next configuration file, you can.

Ubuntu Nginx Installation

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.