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.