CentOS 7 system YUM quick installation LNMP environment tutorial

Source: Internet
Author: User
Tags fpm gpg php script zip centos phpmyadmin

Although the LNMP environment is easy to customize, a long compilation time is too long for small servers. If you can install the environment within 10 minutes, no matter how much.

Then, how can I quickly install the LNMP environment within 10 minutes? The answer is to use YUM for installation.

What YUM?

Explanation on the official website

Yum is a software package manager that instils, updates, and removes packages on RPM-based systems. it automatically computes dependencies and figures out what things shoshould 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
There are two obvious explanations: Simple configuration -- Simple configuration, Fast operation -- Fast operation.

Configure and install

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

 

Configure YUM source

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

To configure the YUM source, you can directly install the Red Hat Package Manager Package or modify the Repository. This article describes how to install the RPM.

First, 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 is the MySQL YUM source. The MySQL official website provides a Configuration tutorial, because this article describes CentOS 7, we only need to install the corresponding RPM package.

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

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

Rpm -- import mysql_pubkey.asc
Install the MySQL RPM Package for CentOS 7 after import:

Rpm-Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
Next is the php yum source. The latest RPM Package of PHP can use 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 is provided. The Nginx official website also provides a Configuration tutorial.

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.

By default, MySQL YUM source is an enabled MySQL-5.6, php yum source is not enabled by default, and Nginx YUM source is an enabled Nginx-1.8 by default.

Go to/etc/yum. repos. d/to edit the file suffixed with. repo. Modify enabled to 1 to enable the file.

Enabling PHP-7.0:

1. Modify/etc/yum. repos. d/remi. repo, and 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; 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
After completing the YUM configuration, clear and generate the YUM cache to make it take effect:

Yum clean all
Yum makecache
 

Install MySQL + PHP + Nginx + phpMyAdmin

The YUM source has been configured. Now you can directly install MySQL + PHP + Nginx + phpMyAdmin:

Yum install-y mysql-community-server nginx 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 above php-* can be installed based on actual usage.

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

 

Configure MySQL

Keep the default MySQL configuration file and run the security configuration once.

Start MySQL:

Systemctl start mysqld. service
Security Configuration MySQL:

Set the root password, delete anonymous users, disable remote root logon, delete the test database, and reload the permission table.

Mysql_secure_installation
 

Configure PHP

By default, the PHP configuration file listens to Port 9000 for communication. For small and single servers without balance of liabilities, you can use unix sock for communication.

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

# Change the listener mode
Listen =/dev/shm/php-fpm-default.sock

# The maximum length of a listener queue is unlimited.
Listen. backlog =-1
# Specify the listener user and user group (required)
Listen. owner = www
Listen. group = www
Start PHP-FPM:

Systemctl start php-fpm.service
 

Configure Nginx

Display the default server access page as the 400 prompt page.

# Create a configuration file named nginx-default.conf
Touch/etc/nginx/conf. d/nginx-default.conf
# Editing the configuration file
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.

Allow HTTP port access through the firewall:

Firewall-cmd -- permanent -- zone = public -- add-service = http
Firewall-cmd -- reload
Start Nginx:

Systemctl start nginx. service
Enter the IP address of the current server in the address bar of the browser and you will see a 400 prompt page.

Advanced! Bind Domain name + site directory + save log + configure file for running PHP:

Server
{
Listen 80; # listening to port 80
Server_name default.com www.default.com; # bind the domain name default.com and www.default.com
Index index.html index.htm index. php; # set the homepage file. The higher the priority
Charset UTF-8; # set webpage encoding

Root/home/wwwroot/default; # set the site root directory

# Run PHP
Location ~ . * \. Php $
    {
Fastcgi_pass 127.0.0.1: 9000 # By default, Port 9000 is used to communicate with PHP.
# Fastcgi_pass unix:/dev/shm/php-fpm-default.sock; # use unix sock to communicate with PHP
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 the file expiration time
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf | flv | mp3 | wma) $
    {
Expires 30d;
    }

# Set the file expiration time
Location ~ . * \. (Js | css) $
    {
Expires 12 h;
    }

# 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;
    }

# Saving logs
Access_log/var/log/nginx/default-access.log main;
Error_log/var/log/nginx/default-error.log crit;
}
 

Configure phpMyAdmin

# Editing the configuration file
Vi etc/phpMyAdmin/config. inc. php
Modify the following content:

$ Cfg ['servers'] [$ I] ['host'] = 'localhost ';
$ Cfg ['servers'] [$ I] ['port'] = '000000 ';
$ Cfg ['servers'] [$ I] ['sockets '] ='/var/lib/mysql. sock ';
$ Cfg ['servers'] [$ I] ['connect _ type'] = 'socket ';
$ Cfg ['servers'] [$ I] ['extension'] = 'mysqli ';
$ Cfg ['servers'] [$ I] ['auth _ type'] = 'cooker ';
$ Cfg ['uploaddir'] = '/tmp ';
$ Cfg ['savedir'] = '/tmp ';
If Nginx uses the above advanced code, then copy the phpMyAdmin directory to/home/wwwroot/default/phpMyAdmin/, you can access through the http://default.com/phpMyAdmin:

# Copy The phpMyAdmin Directory
Cp-a/usr/share/phpMyAdmin/home/wwwroot/default/

# Replace the connection form with the 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

I have already explained how to configure and install it, but I cannot take this step every time? To save time, you have written a one-click installation and management script. You can choose to install 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 a specified file
# Bash lnmp. sh 2> & 1 | tee lnmp. log
Manage sites

Service vhost (start, stop, list, add, edit, del, exit) <domain> <server_name> <index_name> <rewrite_file> Start
Stop
List
Add
Edit
Del delete
Exit. Do nothing.
<Domain>: configuration name, for example, domain
<Server_name>: Domain name list, for example, domain.com and www.domain.com
<Index_name>: Homepage file, for example, index.html, index.htm, index. php
<Rewrite_file>: pseudo-static rule file, which is saved in/etc/nginx/rewrite/for example: nomal. conf
<Host_subdirectory>: whether sub-directory binding, on, or off is supported.
Example:

# Add a website marked as domain
Service vhost add domain domain.com, www.domain.com index.html, index.htm, index. php nomal. conf on

# Start the website marked as domain
Service vhost start domain

# Stop the website marked as domain
Service vhost stop domain

# Edit the website marked as domain
Service vhost edit domain

# Delete a website identified as domain
Service vhost del domain

# List all sites
Service vhost list
Back up data

Service vbackup (start, list, del) <delete name.tar.gz>
Add start
List
Del delete
Example:

# Add a new backup
Service vbackup start

# List backup files
Service vbackup list

# Deleting a backup
Service vbackup del name.tar.gz

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.