CentOS 7 YUM 10-minute Quick Installation LNMP Environment Detailed Tutorial

Keywords: PHP yum Nginx RPM

Source Code Compilation and Installation LNMP Although the environment is easy to customize, for small servers, the long compilation time makes it impossible to wait. It would be much better if the environmental installation could be completed in 10 minutes.

So how to install it quickly in 10 minutes? LNMP Environment, the answer is to use YUM installation.

What YUM?

Explanations given on the official website

yum is a software package manager that installs, updates, and removes packages on RPM-based systems. It automatically computes dependencies and figures out what things should occur to install packages. yum makes it easier to maintain groups of machines without having to manually update each one using rpm.

Features include:

  • Support for multiple repositories
  • Simple configuration
  • Dependency calculation
  • Fast operation
  • RPM-consistent behavior
  • Package group support, including multiple-repository groups
  • Simple interface

Two of the explanations are obvious: Simple configuration -- simple configuration, Fast operation -- fast operation.

configuration setup

Based on this feature of YUM, you can simply and roughly install the LNMP environment.

 

Configure YUM source

The package version in the default YUM source of CentOS 7 may not be the latest. If you want to install the latest package, you have to configure the YUM source.

You can configure YUM source by installing RPM (Red Hat Package Manager) packages directly or modifying Repository. This article explains how to install RPM.

First, you need to install the EPEL (Extra Packages for Enterprise Linux) YUM source to solve the problem that some dependent packages do not exist:

yum install -y epel-release

Next comes the MySQL YUM source. MySQL Official website gives configuration tutorials Because this article explains CentOS 7, we just need to install the corresponding RPM package.

Before installing RPM package, you need to import RPM-GPG-KEY file, otherwise the installation process will be wrong.

Will MySQL RPM-GPG-KEY Save as mysql_pubkey.asc and import:

rpm --import mysql_pubkey.asc

Install the MySQL RPM package of CentOS 7 after importing:

rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

Then there is the PHP YUM source, the latest RPM package of PHP, which can be used. Remi's RPM repository.

Import PHP RPM-GPG-KEY (remi):

rpm --import http://rpms.remirepo.net/RPM-GPG-KEY-remi

Install the PHP RPM (remi) package:

rpm -Uvh http://remi.mirrors.arminco.com/enterprise/remi-release-7.rpm

Finally, the Nginx YUM source. Nginx Official website also gives configuration tutorials..

Import Nginx RPM-GPG-KEY:

rpm --import http://nginx.org/packages/keys/nginx_signing.key

Install the Nginx RPM package:

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

So far, the YUM source has been installed, and the next step is to configure it.

MySQL YUM source is enabled by default MySQL-5.6, PHP YUM source is not enabled by default, and Nginx YUM source is enabled by default Nginx-1.8.

Locate / etc/yum.repos.d /, right Files suffixed with.repo are edited and enabled is modified to 1 to enable.

Enable PHP-7.0:

1. Modify/etc/yum.repos.d/remi.repo to change enabled=0 under [remi] and [remi-test] to enabled=1;

2. Modify/etc/yum.repos.d/remi-php70.repo and change enabled=0 under [remi-php70] to enabled=1;

sed -i "/remi\/mirror/{n;s/enabled=0/enabled=1/g}" /etc/yum.repos.d/remi.repo
sed -i "/test\/mirror/{n;n;s/enabled=0/enabled=1/g}" /etc/yum.repos.d/remi.repo
sed -i "/php70\/mirror/{n;s/enabled=0/enabled=1/g}" /etc/yum.repos.d/remi-php70.repo

Once the YUM configuration is completed, the YUM cache is cleaned up and generated to take effect:

yum clean all
yum makecache

 

Install MySQL + PHP + Nginx + phpMyAdmin

YUM source has been configured, now install MySQL + PHP + Nginx + phpMyAdmin directly:

yum install -y mysql-community-server nginx php php-bcmath php-fpm php-gd php-json php-mbstring php-mcrypt php-mysqlnd php-opcache php-pdo php-pdo_dblib php-pgsql php-recode php-snmp php-soap php-xml php-pecl-zip phpMyAdmin

Note: The php - * installed above can be installed according to actual usage.

After installation, proceed to the next environment configuration, MySQL configuration file in / etc/my.cnf.d/, PHP The configuration file is in / etc/php-fpm.d /, the Nginx configuration file is in / etc/nginx /, phpMyAdmin The configuration file is in / etc/phpMyAdmin /.

 

Configure MySQL

MySQL configuration file remains the default, running a security configuration can be.

Start MySQL:

systemctl start mysqld.service

Secure configuration MySQL:

Setting the root password, deleting anonymous users, banning root remote login, deleting test database, reloading the privilege table, all the way to Y

mysql_secure_installation

 

Configure PHP

The default configuration file of PHP is to listen on port 9000 for communication. For a small single server without debt balancing, it can use unix sock to communicate.

To use unix sock, you need to modify the PHP configuration file:

#Change the way of monitoring
listen = /dev/shm/php-fpm-default.sock

#The maximum length of the listening queue is unlimited
listen.backlog = -1
#Specify listener users and user groups (need to exist)
listen.owner = www
listen.group = www

Start PHP-FPM:

systemctl start php-fpm.service

 

Configure Nginx

Let the server default access display 400 prompt pages.

#New name nginx-default.conf Configuration file
touch /etc/nginx/conf.d/nginx-default.conf
#Editing configuration files
vi /etc/nginx/conf.d/nginx-default.conf

Enter the following information into nginx-default.conf

server
{
    listen 80 default;
    return 400;
}

Press Esc and enter: x to save and exit.

Firewall lets HTTP port access:

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --reload

Start Nginx:

systemctl start nginx.service

At this time, enter the current server IP in the browser address bar and you will see a 400 prompt page.

Advance! Binding Domain Name + Site Directory + Save Log + Run PHP Profile:

server
{
    listen 80; #Listen on port 80
    server_name default.com www.default.com; #Binding Domain Names default.com and www.default.com
    index index.html index.htm index.php; #Setting Home Page Files, the Higher Priority
    charset utf-8; #Setting up Web Coding

    root  /home/wwwroot/default; #Setting the site root directory

    #Function PHP
    location ~ .*\.php$
    {
        fastcgi_pass  127.0.0.1:9000 #By default, port 9000 and PHP Signal communication
        #fastcgi_pass  unix:/dev/shm/php-fpm-default.sock; #Use unix sock and PHP Signal communication
        fastcgi_index index.php;
        fastcgi_param DOCUMENT_ROOT  /home/wwwroot/default; #PHP Document root directory
        fastcgi_param SCRIPT_FILENAME  /home/wwwroot/default$fastcgi_script_name; #PHP Script directory
        include fastcgi_params;
        try_files $uri = 404;
    }

    #Set file expiration time
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$
    {
        expires      30d;
    }

    #Set file expiration time
    location ~ .*\.(js|css)$
    {
        expires      12h;
    }

    #Setting File Access Permissions
    location ~* /templates(/.*)\.(bak|html|htm|ini|old|php|tpl)$ {
        allow 127.0.0.1;
        deny all;
    }

    #Setting File Access Permissions
    location ~* \.(ftpquota|htaccess|htpasswd|asp|aspx|jsp|asa|mdb)?$ {
        deny all;
    }

    #Keep logs
    access_log /var/log/nginx/default-access.log main;
    error_log /var/log/nginx/default-error.log crit;
}

 

Configure phpMyAdmin

# Editing configuration files
vi etc/phpMyAdmin/config.inc.php

Amend the following:

$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['socket'] = '/var/lib/mysql/mysql.sock';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['UploadDir'] = '/tmp';
$cfg['SaveDir'] = '/tmp';

If Nginx uses the above advanced code, then add the phpMyAdmin directory Copy it to / home / wwroot / default / phpMyAdmin / and you can access it at http://default.com/phpMyAdmin:

#copy phpMyAdmin Catalog
cp -a /usr/share/phpMyAdmin /home/wwwroot/default/

#Replace the connection as a directory
rm -rf /home/wwwroot/default/phpMyAdmin/doc/html
cp -a /usr/share/doc/phpMyAdmin-<span class="pl-k">*</span>/html /home/wwwroot/default/phpMyAdmin/doc/

One-click script

The above has explained how to configure and install it, but can't you do it step by step every time? In order to save time, Mai Liang wrote one. One-click Installation Management Script Optional installation of Nginx 1.8/1.9, MySQL 5.5/5.6/5.7 and PHP 5.5/5.6/7.0.

install

yum install -y unzip

wget https://github.com/maicong/LNMP/archive/master.zip

unzip master.zip

cd LNMP-master

bash lnmp.sh

# Output to specified file
# bash lnmp.sh 2>&1 | tee lnmp.log

Managing Sites

service vhost (start,stop,list,add,edit,del,exit) <domain> <server_name> <index_name> <rewrite_file> <host_subdirectory>
  • start
  • stop
  • list
  • add
  • edit
  • del
  • exit Does Nothing
  • <domain>: Configuration name, for example:domain
  • <server_name>: List of domain names, e.g. domain.com,www.domain.com
  • <index_name>: Home page files, such as index.html,index.htm,index.php
  • <rewrite_file>: Pseudo-static rule file, saved in / etc/nginx/rewrite/ e.g. nomal.conf
  • <host_subdirectory>: Supports subdirectory binding, on or off

Examples:

#Add an identity as domain Website
service vhost add domain domain.com,www.domain.com index.html,index.htm,index.php nomal.conf on

#Startup ID is domain Website
service vhost start domain

#Stop marked as domain Website
service vhost stop domain

#The edit is identified as domain Website
service vhost edit domain

#Delete the identification as domain Website
service vhost del domain

#List all sites
service vhost list

Backup data

 service vbackup (start,list,del) <delete name.tar.gz>
  • start to add
  • list
  • del

Examples:

#Add a new backup
service vbackup start

#List backup files
service vbackup list

#Delete a backup
service vbackup del name.tar.gz


Posted by jcrensha627 on Wed, 10 Jul 2019 14:38:01 -0700