Install Nginx/PHP 7/MySQL 16.04 (LEMP) on Ubuntu 5.7 LTS)

Source: Internet
Author: User
Tags apcu nginx server

Install Nginx/PHP 7/MySQL 16.04 (LEMP) on Ubuntu 5.7 LTS)

Nginx (read engine x) is a free and open-source high-performance HTTP service. Nginx is stable, rich feature sets, simple configuration, and low resource consumption. This tutorial explains how to use PHP7 support (via PHP-FPM) and MySQL5.7 support (LEMP = LINUX + nginx (pronounced "engine x") + MySQL + PHP) install the Nginx server on the Ubuntu 16.04 server.

1. Preliminary description

In this tutorial, I use the IP address 192.168.1.100 and the host name server1.example.com. These settings may be different from yours, so you have to change them as appropriate.

All the steps I run use the root permission in this tutorial, so make sure that you log on as root:

Install php mysql phpmyadmin ubuntu 16.04

2. Install MySQL 5.7

Run the following command to install MySQL:

Apt-get-y install mysql-server mysql-client

You will be asked to provide the MySQL root User Password:

New password for the MySQL "root" user: <-yourrootsqlpassword
Repeat password for the MySQL "root" user: <-yourrootsqlpassword

Install phpmyadmin ubuntu 16.04 apache

To ensure the database server and delete anonymous users and Test Databases, run the mysql_secure_installation command.

Mysql_secure_installation

You will ask these questions:

Root @ server1 :~ # Mysql_secure_installation

Protects MySQL Server deployment.

Enter password for user root: <-Enter the MySQL root password

Validate password plugin can be used to test passwords
And improve security. It checks the strength of password
And allows the users to set only those passwords which are
Secure enough. wocould you like to setup validate password plugin?

Ubuntu 16.04 phpmyadmin install

Phpmyadmin not working ubuntu 16.04

Press y | Y for Yes, any other key for No: <-Press y if you want this function or press Enter otherwise.
Using existing password for root.
Change the password for root? (Press y | Y for Yes, any other key for No): <-Press enter

... Skipping.
By default, a MySQL installation has an anonymous user,

Setup phpmyadmin ubuntu 16.04

How to install phpmyadmin in ubuntu 16.04 using terminal
Allowing anyone to log into MySQL without having to have
A user account created for them. This is intended only
Testing, and to make the installation go a bit smoother.
You shoshould remove them before moving into a production
Environment.

Phpmyadmin install ubuntu 16.04

Remove anonymous users? (Press y | Y for Yes, any other key for No): <-y
Success.

Normally, root shoshould only be allowed to connect from
'Localhost'. This ensures that someone cannot guess
The root password from the network.

Disallow root login remotely? (Press y | Y for Yes, any other key for No): <-y
Success.

By default, MySQL comes with a database named 'test' that
Anyone can access. This is also intended only for testing,
And shoshould be removed before moving into a production
Environment.

Remove test database and access to it? (Press y | Y for Yes, any other key for No): <-y
-Dropping test database...
Success.

-Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
Made so far will take effect immediately.

Reload privilege tables now? (Press y | Y for Yes, any other key for No): <-y
Success.

All done!

MySQL is secured now.

3. Install Nginx

If you have already installed Apache2, use these commands to delete and then install nginx:

Service apache2 stop
Update-rc.d-f apache2 remove
Apt-get remove apache2

Ubuntu16.04 has an Nginx installation package. We can install it.

Apt-get-y install nginx

Start nginx afterwards:

Service nginx start

Enter the IP address or host name of your Web server to your browser (for example, http: // 192.168.1.100). You should see the following page:


The default nginx document root directory in Ubuntu16.04 is/var/www/html.

 

4. install PHP 7

We can make nginx's PHP work PHP-FPM (FastCGI Process Manager) is for any scale of websites, especially for busy websites, some additional functions are useful to replace PHP's FastCGI Implementation). We install the following:

Apt-get-y install php7.0-fpm

 

5 configure nginx

Open the configuration file/etc/nginx. conf:

Nano/etc/nginx. conf

Configuration is easy to understand (you can click official Tutorials: http://wiki.nginx.org/NginxFullExample or: http://wiki.nginx.org/NginxFullExample2)

First (optional) Adjust keepalive_timeout to a reasonable value:

[...]    keepalive_timeout   2;[...]

Virtual host server {} container definition. The default virtual host is/etc/nginx/sites-available/default defined in the file. Let's modify it, as shown below:

Nano/etc/nginx/sites-available/default

[...]server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { include snippets/fastcgi-php.conf; # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.0-fpm.sock; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht {  deny all; }}[...]

Server_name _; so that this is a default capture of all virtual hosts (of course, you can also like here www.example.com to specify the host name ).

Root directory/var/www/html; indicates the root directory of the document/var/www/html.

Important components of PHP ~ \. Php $ {} stanza. uncomment it to enable it.

Now save the file and reload nginx:

Service nginx reload

Next open/etc/php/7.0/fpm/php. ini...

Nano/etc/php/7.0/fpm/php. ini

Set cgi. fix_pathinfo = 0:

[...]; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.; http://php.net/cgi.fix-pathinfocgi.fix_pathinfo=0[...]

Reload the PHP-FPM:

 

Service php7.0-fpm reload

Create a probe file/var/www/html:

Nano/var/www/html/info. php

<?phpphpinfo();?>

Browser access (e.g. http: // 192.168.1.100/info. php ):


 

6. Obtain PHP 7 Support for MySQL

Search for the modules supported by PHP:

Apt-cache search php7.0

Run the following command to install the SDK:

Apt-get-y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0 -sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext

APCu is an extension of the PHP Opcache module in PHP7. It supports APC caching (for example, WordPress plug-in caching) software with compatibility features.

You can install APCu as follows:

Apt-get-y install php-apcu

Reload the PHP-FPM:

Service php7.0-fpm reload

Refresh the http: // 192.168.1.100/info. php browser to check the module installation:


 

7 Let the PHP-FPM use TCP Connection

By default, the PHP-FPM listens to/var/run/php/php7.0-fpm. sock. in addition, you can also make the PHP-FPM try TCP connection, open the file/etc/php/7.0/fpm/pool. d/www. conf...

Nano/etc/php/7.0/fpm/pool. d/www. conf

Modify as follows:

[...];listen = /var/run/php5-fpm.socklisten = 127.0.0.1:9000[...]

This will make the PHP-FPM port 9000 listen to IP127.0.0.1 (local host ). Make sure that the port you are using is not used on your system.

Then reload PHP-FPM:

Php7.0-fpm reload

Next, use your nginx configuration and all virtual hosts, and change the fastcgi_pass UNIX line:/var/run/php/php7.0-fpm. sock; tofastcgi_pass127.0.0.1: 9000;, as shown below:

Nano/etc/nginx/sites-available/default

[...]        location ~ \.php$ { include snippets/fastcgi-php.conf; # With php7.0-cgi alone: fastcgi_pass 127.0.0.1:9000; # With php7.0-fpm: # fastcgi_pass unix:/run/php/php7.0-fpm.sock; }[...]

Finally, reload nginx:

Service nginx reload

OK. Nginx LEMP server has been installed.

CentOS 5.6 + Nginx 1.0 + PHP 5.3.6 + MySQL 5.5.11 build the LEMP (X64) Platform

Build a high-performance WEB server LEMP using Nginx in Linux

Example of LAMP architecture collaborative application-phpMyAdmin

PhpMyAdmin and Wordpress for LAMP applications

PhpMyAdmin logon timeout Solution

Install phpMyAdmin and Adminer in Ubuntu

Implement SSL functions based on LAMP and install phpMyAdmin

Configure the LAMP + phpMyAdmin PHP (5.5.9) development environment in Ubuntu 14.04



Related Article

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.