CentOS 7 build LNMP environment

The LNMP environment refers to a website server architecture composed of Nginx + MySQL/MariaDB + PHP under the Linux system. This document describes how to manually set up an LNMP environment on Tencent Cloud cloud server(CVM).

1. Install Nginx

Execute the following command to create the nginx.repo file under /etc/yum.repos.d/:

vi /etc/yum.repos.d/nginx.repo

Press "i" to switch to edit mode and write the following:

[ nginx] name = nginx repobaseurl = https://nginx.org/packages/mainline/centos/7/$basearch/gpgcheck =0 enabled =1

Press "Esc", enter ":wq", save the file and return.

Execute the following command to install nginx:

yum install -y nginx

Execute the following command to open the nginx.conf file:

vim /etc/nginx/nginx.conf

Press "i" to switch to edit mode and edit the nginx.conf file. Find server{...} and replace the corresponding configuration information in the server braces with the following. Used to cancel the monitoring of IPv6 addresses, and configure Nginx to achieve linkage with PHP:

Vim Tips: Use Ctrl+F to page down and Ctrl+B to page up to view the file.

server { listen       80; root   /usr/share/nginx/html; server_name  localhost; #charset koi8-r; #access_log  /var/log/nginx/log/host.access.log  main; # location /{       index index.php index.html index.htm;} #error_page  404/404.html; #redirect server error pages to the static page /50x.html # error_page   500502503504/50x.html; location =/50x.html {   root   /usr/share/nginx/html;} #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~.php$ {   fastcgi_pass   127.0.0.1:9000;   fastcgi_index  index.php;   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;   include        fastcgi_params;}}

If server{...} is not found in the nginx.conf file, please add it above include/etc/nginx/conf.d/*conf;. As shown below:

Press "Esc", enter ":wq", save the file and return. Execute the following command to start Nginx:

systemctl start nginx

Execute the following command to set Nginx to start automatically after booting:

systemctl enable nginx

Visit the following address in the local browser to check whether the Nginx service is running normally:

http://Public IP of the cloud server instance

If the display is as follows, the Nginx installation configuration is successful:

2. Install the database##

Execute the following command to check whether MariaDB is installed in the system:

rpm -qa | grep -i mariadb

To avoid conflicts caused by different installation versions, execute the following command to remove the installed MariaDB:

yum -y remove package name
vi /etc/yum.repos.d/MariaDB.repo

Press "i" to switch to edit mode, write the following to add MariaDB software library:

Note that different operating systems have different MariaDB software libraries. You can go to MariaDB official website to get installation information of MariaDB software libraries for other operating systems.

# MariaDB 10.4 CentOS repository list - created 2019-11-0511:56 UTC# http://downloads.mariadb.org/mariadb/repositories/[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/10.4/centos7-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1

Press "Esc", enter ":wq", save the file and return. Execute the following command to install MariaDB:

yum -y install MariaDB-client MariaDB-server

Execute the following command to start MariaDB service:

systemctl start mariadb

Execute the following command to set MariaDB to start automatically after booting:

systemctl enable mariadb

Execute the following command to verify that MariaDB is installed successfully:

mysql

If the results are as follows, the installation is successful:

Execute the following command to exit MariaDB:

\ q

3. Install and configure PHP

Execute the following commands in turn to update the software source of PHP in yum:

rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Execute the following command to install the packages required by PHP 7.2:

yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64

Execute the following command to start the PHP-FPM service:

systemctl start php-fpm

Execute the following command to set the PHP-FPM service to start automatically after booting:

systemctl enable php-fpm

4. Verify environment configuration##

After completing the environment configuration, you can verify whether the LNMP environment is successfully set up through the following. Execute the following command to create a test file:

echo "<?php phpinfo(); ?>">>/usr/share/nginx/html/index.php

Execute the following command to restart the Nginx service:

systemctl restart nginx

Visit the following address in the local browser to check whether the environment configuration is successful:

http://Public IP of the cloud server instance

If the result is as follows, the environment configuration is successful:

Recommended Posts

CentOS6.7 build LNMP environment
Centos7.6 build LNMP environment
CentOS 7 build LNMP environment
Centos build lnmp
Build docker environment under Centos6.5
Build Discuz Forum in LNMP Environment under CentOS7
Build Dedecms website in LNMP environment under CentOS7
Centos-6.5 installation and deployment of LNMP environment
Steps to build LNMP environment on ubuntu 20.04
(1) Centos7 installation to build a cluster environment
[PHP] Build a PHP operating environment under CentOS
CentOS7.3 64 bit, build Zabbix3.4
CentOS build private git
install LNMP on centos7.4
Linux (centos7) build gitlab
Build k8s1.9.9 on centos7
Hadoop environment construction (centos7)
lamp (centos7) installation lamp environment
Centos7 build Kubernetes cluster
Centos6.9 install npm environment
Jenkins build on centos
Build LEMP (Linux+Nginx+MySQL+PHP) environment under CentOS 8.1 (detailed tutorial)
Centos7 configure nodejs environment
Centos6.5 compile and install LNMP architecture web environment
How to build a LAMP environment on centos7.2
Configure CentOS7 GPU environment
Build a basic environment for Java development under Centos7
[CentOS environment deployment] Java7/Java8 deployment under CentOS
CentOs7.3 build Solr stand-alone service
Build OpenV** Server under CentOS7
CentOs7.3 build RabbitMQ 3.6 stand-alone service
Ubuntu18.04LTS quickly build CUDA environment
Build zabbix monitoring zabbix4.2 in CentOS7.6
CentOS 7 install JAVA environment (JDK 1.8)
Build OpenLDAP server under CentOS7
SkyWalking study notes (CentOS environment)
Build MariaDB replication on CentOS
Centos7 set up GitBook environment
CentOS 7.2 deploy Node.js development environment
CentOS install nginx+tomcat+java+mysql operating environment
CentOs7.3 build ZooKeeper-3.4.9 stand-alone service
Centos6 set up GitBook environment
ubuntu build python development environment
CentOs7.3 build SolrCloud cluster service
Centos7 deploys python3 virtual environment
Centos7.4 environment installation lamp-php7.0 tutorial
CentOS8 deploys LNMP environment to compile and install mysql8.0.29 tutorial details
CentOS 8 (2)
CentOS 7 configure Ruby language development environment
CentOS8.1 build Gitlab server detailed tutorial
Ubuntu16.04 build php5.6 Web server environment
CentOS 7 configure php language development environment
CentOS7 compile and install L(A|N)MP environment
Build an FTP server under centos7
CentOS 8 (1)
Build Elasticsearch 6.2.4 (centos) based on docker
(centos7) linux build nginx load balancing build
Centos7 build java web server tomcat
Configure python3 environment on centos7 and
Build Discuz Forum based on CentOS
Build Yum private warehouse in Centos7.3