Home > Backend Development > PHP Tutorial > The easiest way to build Nginx and PHP environments in Ubuntu_PHP Tutorial

The easiest way to build Nginx and PHP environments in Ubuntu_PHP Tutorial

WBOY
Release: 2016-07-13 10:05:03
Original
831 people have browsed it

The simplest way to build Nginx and PHP environments in Ubuntu

This article mainly introduces the simplest method to build Nginx and PHP environments in Ubuntu. This article explains the use of apt -The get tool installs Nginx and PHP environments, and explains the basic configuration. Friends in need can refer to it

Foreword: The results from Baidu are very misleading, and some articles say that others are cheating, but he himself is also cheating. Please be kind to the industry. Google is still reliable.

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

The default installation is nginx 1.2.5, php5.4.9

Install first:

The code is as follows:


sudo apt-get install nginx php5-fpm
I passed the test on a newly installed Ubuntu 13. It is really 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 that if you use gedit instead of vi to edit, you should edit the default file under site-available. If you edit the default under site-enabled, gedit will generate a "default~" backup by default when saving. This backup It will also be regarded as an enabled configuration file by nginx and cause an error and failure to start. The safest approach is to manually delete the backup files after editing the files under site-available.

Find the location ~ .php$, uncomment the 5th line, it will become like this:

The code is as follows:


location ~ .php$ {
# fastcgi_split_path_info ^(.+.php)(/.+)$;
# # NOTE: You should 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;
}

That’s it!

Start nginx:

The code is as follows:


sudo service nginx start
Extensions:

1. In the default file, find

The code is as follows:


index index.html index.htm;
This line, add it as

The code is as follows:


index index.html index.htm index.php;
This allows you to use a php file as the default homepage

2.default file, add

in the location / {} directive of the server{} directive

The code is as follows:


autoindex on;
When 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. If you modify it yourself, you can use that folder as the root directory of the website

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963979.htmlTechArticleThe easiest way to build Nginx and PHP environments in Ubuntu. This article mainly introduces the building of Nginx and PHP environments in Ubuntu. The simplest method, this article explains is to use the apt-get tool to install Nginx,...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template