Install nginx and web service configuration in Ubuntu

Source: Internet
Author: User

Install nginx in Ubuntu

Sudo apt-Get install nginx

After Ubuntu is installed, the file structure is roughly as follows:

All configuration files are under/etc/nginx, and each virtual host is already under/etc/nginx/sites-available.

Program file in/usr/sbin/nginx

Logs are stored in/var/log/nginx.

The Startup Script nginx has been created under/etc/init. d /.

The default virtual host directory is/var/www/nginx-default.

Start nginx

Sudo/etc/init. d/nginx start

Then you can access http: // localhost/. Everything is normal! If it cannot be accessed, do not continue. Check the cause and then continue.

Nginx default page

Configure PHP and MySQL

Install PHP and MySQL

Install PHP and MySQL:

Sudo apt-Get install php5-cli php5-cgi mysql-server php5-mysql

Install FastCGI

The/usr/bin/spawn-fcgi file is used to manage FastCGI. It originally belongs to the Lighttpd package, but after 9.10, spawn-fcgi is separated into a separate package:

Sudo apt-Get install spawn-fcgi

Configure nginx

Modify the nginx configuration file:/etc/nginx/sites-available/default modify the Host Name:

SERVER_NAME localhost;

Modify the row of index:

Index index. php index.html index.htm;

Remove the following comments to support PHP scripts:

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;

}

Restart nginx:

/Etc/init. d/nginx stop

/Etc/init. d/nginx start

Start FastCGI PHP:

Spawn-fcgi-A 127.0.0.1-P 9000-C 10-u www-data-F/usr/bin/PHP-CGI

To enable PHP-CGI to boot automatically:

CD/etc/init. d

CP nginx PHP-CGI

Vim PHP-CGI

Replace nginx with PHP-CGI

And modify the corresponding part:

Daemon =/usr/bin/spawn-fcgi

Daemon_opts = "-A 127.0.0.1-P 9000-C 10-u www-data-F/usr/bin/PHP-cgi"

...

Stop)

Echo-n "Stopping $ Desc :"

Pkill-9 PHP-CGI

Echo "$ name ."

Run rcconf to set PHP-CGI to start automatically

Create and test phpinfo:

Sudo VI/var/www/nginx-default/info. php

Open http: // localhost/info. php.

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.