Abstract:

preface

In the ERA of VPS before the popularity of cloud computing, the network environment was basically supported by LNMP (Linux + Nginx + MySQL + PHP). Because it is easy to configure and performs well on small configuration machines compared to LAMP (Linux + Apache Httpd + MySQL + PHP). But the LNMP update is much more than that.

This tutorial explains how to configure an advanced LNMP environment with excellent performance, flexibility, freedom, and easy upgrade. It consists of Ubuntu + OpenResty + MariaDB + PHP, compatible with LNMP habits, but more flexible and reliable.

To prepare

The cloud wing plan

Student users can purchase ECS with certain configuration after student authentication on aliyun official website, only 9.9 yuan per month, student users do not need to worry about spending too much on the server.

User after students after the certification can be in the related website to buy, address: promotion.aliyun.com/ntms/campus… , bought a good server can go to just registered account management in the management console to view the server and some of its configuration.

The remote control

【 cloud computing 1024 kinds of play 】 Use DMS as long as a browser easy operation and maintenance tasks 【 cloud computing 1024 kinds of play 】ECS and lightweight application server remote control introduction

Setting a Security Group (Major)

If you don’t set up a security group, you can’t tell whether it’s inaccessible or a compile failure.

Need to open: ports 80 and 443

[Cloud computing 1024 kinds of play] make good use of ali Cloud security group

The installation

OpenResty

For better performance and flexibility, OpenResty chose a compiled approach. OpenResty is a high performance Web platform based on Nginx and Lua that is very scalable for better server performance. The tutorial will rely entirely on the dependencies in the Linux distribution build without the late maintenance costs of compilation.

How to build a high performance OpenResty

PHP

The PHP installed by the software source runs on /run/ PHP /php7.2-fpm. Sock in Unix Socket state by default, which is better than using TCP to localhost:9000.

Install software source expansion

Install software source development tools:

apt -y install software-properties-commonCopy the code

To add Ondřej Sury’s PHP PPA source, press enter once:

add-apt-repository ppa:ondrej/php  Copy the code

Update software source cache:

apt updateCopy the code

Install the software

Install PHP7.2:

Apt install php7.2- FPM php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php7.2- XML php7.2- XMLRPC php7.2-zip Php7.2 opcache -- yCopy the code

Install PHP7.1:

Apt install php7.1- FPM php7.1-mysql php7.1-curl php7.1-gd php7.1-mbstring php7.1- McRypt php7.1- XML php7.1- XMLRPC Php7.1 - zip php7.1 - opcache - yCopy the code

Install PHP7.0:

Apt install php7.0- FPM php7.0-mysql php7.0-curl php7.0-gd php7.0-mbstring php7.0- McRypt php7.0- XML php7.0- XMLRPC Php7.0 - zip php7.0 - opcache - yCopy the code

Install PHP5.6:

Apt install php5.6- FPM php5.6-mysql php5.6-curl php5.6-gd php5.6-mbstring php5.6- McRypt php5.6- XML php5.6- XMLRPC Php5.6 - zip php5.6 - opcache - yCopy the code

Set up the PHP

Take PHP7.2 as an example. For other versions, just change the version number to your own. After the installation is complete, edit /etc/php/7.2/fpm/php.ini to replace it. Cgi. fix_pathinfo=1 is cgi.fix_pathinfo=0.

sed -i 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/'/ etc/PHP / 7.2 / FPM/PHP iniCopy the code

Management of PHP

The installation is ready to restart first! More operations:

Systemctl restart php7.2 - FPM# to restartSystemctl start php7.2 - FPM# startSystemctl stop php7.2 - FPM# closeSystemctl status php7.2 - FPM# Check statusCopy the code

To view the current PHP version:

php -vCopy the code

MariaDB

MariaDB is a branch of MySQL that is maintained by the open source community. The purpose of MariaDB under the GPL license is to be fully compatible with MySQL, including apis and command lines. Make it an easy replacement for MySQL.

Install MariaDB and manage it via DMS

It can realize efficient and visual management of MariaDB database through the DMS product of Ali Cloud, which is intuitive and efficient.

Set up the

There is no point in simply installing OpenResty, MariaDB, and PHP without combining them. So how do you create a virtual child host and have OpenResty load phP-fPM?

The default host installs probes and phpMyAdmin

Open the PHP – FPM

To/usr/local/openresty/nginx/conf/nginx. This period of change in the conf, PHP version is below 7.2, which also joined the other versions remember prevent cross-site parameters changes:

######################## default ############################
  server {
  ## Run port
  listen 80; 
  ## This means that this setting is used for all non-specified domains
  server_name _; 

  access_log /data/wwwlogs/access_nginx.log combined; # log directory
  root /data/wwwroot/default; # site file directory
  index index.html index.htm index.php; # Home page file priority

  ##PHPThe location ~ [^ /] \. PHP (/ | $) {fastcgi_pass Unix: / run/PHP/php7.2 - FPM. The sock. fastcgi_index index.php; include fastcgi.conf; fastcgi_param PHP_VALUE"open_basedir=$document_root:/tmp/:/proc/";
    }

  Everything below ## is cache
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
    }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
    }
  location ~ /\.ht {
    deny all;
    }
  }
Copy the code

Download the probe

cd /data/wwwroot/default
wget http://www.yahei.net/tz/tz.zip
unzip tz.zipCopy the code

Visit http://yourip/tz.php to see the friendly Yahei probe.

Download the phpMyAdmin

cd/ data/below/default wget unzip at https://files.phpmyadmin.net/phpMyAdmin/4.7.1/phpMyAdmin-4.7.1-all-languages.zip PhpMyAdmin - 4.7.1 - all - languages.zip mv phpMyAdmin - 4.7.1 - all - languages pmaCopy the code

Visit http://yourip/pma to see the friendly phpMyAdmin.

Virtual subhost

Create a virtual sub-host for the domain name, first create a directory to store the content:

Mkdir -p /data/wwwroot/ Host directory name mkdir -p /usr/local/openresty/nginx/conf/vhost/Copy the code

Next, to create the child host configuration file, remember to server_name Yourdomian; Change your domain name to server_name:

cat >> /usr/local/openresty/nginx/conf/vhost/yourdomian.conf << EOF  
  server {
  ## Run port
  listen 80; 

  ## need to change your domain name here
  server_name yourdomian; 

  access_log /data/wwwlogs/access_nginx.log combined; # log directory
  root /data/wwwroot/yourdir; # site file directory
  index index.html index.htm index.php; # Home page file priority

  ##PHPThe location ~ [^ /] \. PHP (/ | $) {fastcgi_pass Unix: / run/PHP/php7.2 - FPM. The sock. fastcgi_index index.php; include fastcgi.conf; fastcgi_param PHP_VALUE"open_basedir=$document_root:/tmp/:/proc/";
    }

  Everything below ## is cachelocation ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ { expires 30d; access_log off; } location ~ .*\.(js|css)? $ { expires 7d; access_log off; } location ~ /\.ht { deny all; } } EOFCopy the code

Then restart OpenResty and visit http:// your domain name to see 403 of the site:

nginx -s reloadCopy the code

update

Some of the most rogue tutorials are those that install an LNMP environment but don’t provide a way to update OpenResty, ariaDB, and PHP. Especially for compiled tutorials, upgrading is a problem, which greatly increases the user’s security risk and learning cost.

However, the convenience of our LNMP environment is that it is very easy to upgrade.

run

apt update && apt upgrade Copy the code

PHP, MariaDB and Ubuntu components can be updated and upgraded, very fast and convenient. The OpenResty upgrade tutorial will be written later

conclusion

Learn to install the LNMP environment basically unless you have some very old versions. Will be able to eat all the PHP program installation, I hope you can apply to their Linux learning.