The easiest way to build Nginx and PHP environments in Ubuntu

Source: Internet
Author: User
Tags linux mint
This article mainly introduces the simplest way to set up Nginx and PHP environments in Ubuntu. This article describes how to use the apt-get tool to install the Nginx and PHP environments and explains the basic configurations, if you need a friend, you can refer to the following preface: Baidu's results are good, and some articles say that other people are not good at it, but he is also confused. Please feel the conscience of the industry. Google is still reliable.

System environment: Both Ubuntu 13 and Linux Mint 15 pass.

Nginx 1.2.5 and php5.4.9 are installed by default.

First install:

The code is as follows:


Sudo apt-get install nginx php5-fpm


I passed the test on the newly installed Ubuntu13. it is enough to install only these two things.

Then edit the configuration file.

The code is as follows:


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


Note: If you are using gedit instead of vi, you should edit the default file under site-available. if you are editing the default file under site-enabled, because a "default ~" is generated by default when gedit is saved ~" . It is safe to manually delete backup files after editing files under site-available.

Locate location ~ Where \. php $ is located, five lines of uncomment will become like this:

The code is as follows:


Location ~ \. Php $ {
# Fastcgi_split_path_info ^ (. + \. php) (/. +) $;
# NOTE: You shoshould have "cgi. fix_pathinfo = 0;" in php. ini
#
# With php5-cgi alone:
# Fastcgi_pass 127.0.0.1: 9000;
# With php5-fpm:
Fastcgi_pass unix:/var/run/php5-fpm.sock;
Fastcgi_index index. php;
Include fastcgi_params;
}

This becomes!

Start nginx:

The code is as follows:


Sudo service nginx start


Extension:

1. in the default file, find

The code is as follows:


Index index.html index.htm;


This line is added

The code is as follows:


Index index.html index.htm index. php;


You can use the php file as the default homepage.

2. in the default file, add

The code is as follows:


Autoindex on;


If there is no index file in the folder, the file will be automatically indexed.

3. the root line of the server {} indicator is the root directory of the file. you can modify the folder as the root directory of the website.

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.