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).
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:
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
MariaDB.repo
file under /etc/yum.repos.d/
: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
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
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