LNMP Environment Construction and nginx Multi-site configuration under Ubuntu system

Source: Internet
Author: User
Tags curl fpm log log blank page

Recently need to use Ubuntu as a server to build LNMP environment, the way to write down the process to share with you. If there are any deficiencies, we welcome different views. (The default reader of this article is already familiar with the use of related Linux commands, such as creating files and folders, editing file commands, and so on.) )

Operating system: Ubuntu 15.10

This system is newly installed, so there is no nginx, MySQL and PHP environment. If you have previously installed these environments, you have to first uninstall the previous software.

First, install MySQL

Direct Input command: Sudoapt-get install Mysql-server mysql-client

The middle requires you to enter the root account password, as required to operate on it.

Second, install Nginx

Direct input command: sudo apt-get install Nginx

In the local browser, enter 127.0.0.1 and the following page instructions appear to install.

Third, installation PHP5

Direct input command: sudo apt-get install PHP5-FPM

Installation will also need to install the expansion, such as:

Php5-mysql, PHP5-GD, Php5-json, Php5-curl ...

Specifically, you can use the command sudo apt-cache search php5 to view the extension information.

Then use the command sudo apt-get install php5-mysql php5-gd Php5-json php5-curl to expand the installation.

After installing a test.php file test, execute the result

<?php

$a = "php test\n";

echo $a;

?>

PHP installed successfully!

Installation process here is finished, next is the configuration let Nginx do PHP5-FPM agent. (Do not understand php5-fpm is what the ghost of the classmate to search it, the back and fastcgi and other concepts should be understood. Great god please ignore ~)

Four, configure Nginx to do the agent

Enter the/etc/nginx directory and open the Nginx.conf configuration file to see a line at the bottom of the HTTP module:

include/etc/nginx/sites-enabled/*;

So we can create a new configuration file test.conf in the/etc/nginx/sites-enables directory, which reads:

Where Fastcgi_pass is set to 127.0.0.1:9000, then it needs to be found in the/etc/php5/fpm/pool.d/www.conf file:

Listen =/var/run/php5-fpm.sock

Comment It and add a line below it:

Listen = 127.0.0.1:9000

Save after exiting restart Php5-fpm:service php5-fpm restart

8080 ports are configured for the test.conf, so also configure the firewall to turn on port 8080 (the same as the configuration port of the subsequent multisite): sudo ufw allow 8080

In the root directory of the configured site, that is,/var/www/test new file index.php:

<?php

Phpinfo ();

?>

Configured in the local browser input: 127.0.0.1:8080 unexpectedly appear blank page, find/etc/nginx/fastcgi_params, that is, the previous test.conf file include Fastcgi_params file, Add a line to its head:

Fastcgi_param script_filename $document _root$fastcgi_script_name; #设置脚本文件请求的路径.

Restart Nginx after saving or use the command: Nginx–s reload to reload the configuration file. To browser refresh, success

Five, different port multi-site configuration

Just like the first site, create a new two files under the/var/www directory, test2 and Test3, respectively, as a directory for the other two sites.

New test file/var/www/test2/index.php:

<?php

$test = "Test2 site \ n";

Echo $test;

?>

New test file/var/www/test3/index.php:

<?php

$test = "Test3 site \ n";

Echo $test;

?>

Then create a new two site profile in the/etc/nginx/sites-enabled directory, just like the newly created test.conf. Configuration file:/etc/nginx/sites-enabled/test2.conf

Configuration file:/etc/nginx/sites-enabled/test3.conf

After configuration, sudo nginx–s reload reload the configuration file. The firewall turns on the corresponding 8082 and 8083 ports.

Test Site test2: Local browser input: 127.0.0.1:8082

Test Site test3: Local browser input: 127.0.0.1:8083

Six, 80 port long site configuration

Above is the different port multiple site configuration, below we look at 80 port how to long site configuration

The above operation has implemented different ports for multiple sites configuration, now modify/etc/nginx/sites-enable/test2.conf and/etc/nginx/sites-enable/ Test3.conf two configuration files to change the listening port to 80 ports. The site Directory does not change:

Reload nginx config file after change

Use the server_name that you just set up in the configuration file to access, that is, test2.com and test3.com, and you have to modify the host file. Opens the/etc/host file with two new lines:

127.0.0.1 test2.com

127.0.0.1 test3.com

Open the local browser to enter test2.com and test3.com respectively to view the results:

Configuration is successful!

Summarize:

1, every time after modifying the Nginx configuration file, you need to reload the configuration file, you can also restart. The same is true of PHP5-FPM.

2, although this article explains how to build the environment, and configuration environment, but for the corresponding environment of the operating principle has not done much discussion. So, to be really familiar with the operating principle of the corresponding environment, but also to take some effort to understand the corresponding knowledge points. For example, the role of the Fastcgi_params file, the function of each module in the Nginx configuration file, and the mechanism of PHP5-FPM.

3, installation configuration process will inevitably appear some unexpected problems, in this case to learn to analyze the log positioning problems. The log is generally placed in the/var/log directory, such as just configure the first site is access encountered blank page, but see/var/log/nginx/ Access.log log shows the status code is 200, which indicates that Nginx is receiving the request, but did not send the requested content to PHP5-FPM, so locate the problem is in the Nginx and PHP5-FPM communication.

LNMP Environment Construction and nginx Multi-site configuration under Ubuntu system

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.