The LNMP environment is a website server architecture consisting of Nginx, MySQL or MariaDB, and PHP running on Linux. This document describes how to manually set up the LNMP environment on a Tencent Cloud CVM.
To manually set up the LNMP environment, you should familiarize yourself with common Linux commands and understand the usage and version compatibility of the software to be installed.
The following software is used to build the LNMP environment.
CentOS is a distribution of the Linux operating system. This document uses CentOS 8.0 as an example.
Nginx is a web server. This document uses Nginx 1.18.0 as an example.
MySQL is a database software. This document uses MySQL 8.0.21 as an example.
PHP is a scripting language. This document uses PHP 7.4.11 as an example.
A Linux CVM is required to set up a LNMP environment. If you have not purchased a Linux CVM yet, see Customizing Linux CVM Configurations.
See Log into Linux Instance Using Standard Login Method. You can also use other login methods that you are more comfortable with:
Run the following command to install Nginx.
This document takes installing Nginx 1.18.0 as an example. You can view Nginx installation package to obtain more versions that are compatible with CentOS 8.
dnf -y install http://nginx.org/packages/centos/8/x86_64/RPMS/nginx-1.18.0-1.el8.ngx.x86_64.rpm
Run the following command to view the Nginx version.
If the following result is returned, it indicates that Nginx has been successfully installed.
nginx version: nginx/1.18.0
/etc/nginx/conf.d/*.conf under the
include configuration item indicates the default path of the Nginx configuration file.
4. Run the following commands in sequence to back up the configuration file under the default path.
cp default.conf default.conf.bak
location, as shown below:
location ~ \\.php$and modify the following configuration items:
rootto your website root directory. This document uses
/usr/share/nginx/html;as an example.
unix:/run/php-fpm/www.sock;. This configuration should be the same as
/etc/php-fpm.d/www.conffile, because Nginx is associated with PHP-FPM through UNIX sockets.
systemctl start nginx
systemctl enable nginx
Run the following command to install MySQL.
dnf -y install
Run the following command to view the MySQL version.
If the following result is returned, it indicates that MySQL has been successfully installed.
mysql Ver 8.0.21 for Linux on x86_64 (Source distribution)
systemctl enable --now mysqld
systemctl status mysqld
Perform the following steps:
yand press Enter to start configurations.
2and press Enter.
yto confirm the password.
yand press Enter to remove anonymous users.
yand press Enter.
nand press Enter.
yand press Enter to delete the test library and access permission to it.
yand press Enter to reload the authorization table.
dnf -y install epel-release
dnf update epel-release
dnf clean all
Run the following command to install the REMI repository.
Skip this step if you install PHP of version other than 7.4.11.
dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Run the following command to start the PHP 7.4 component.
dnf module install php:remi-7.4
Run the following command to install the required PHP components.
dnf install php php-curl php-dom php-exif php-fileinfo php-fpm php-gd php-hash php-json php-mbstring php-mysqli php-openssl php-pcre php-xml libsodium
Run the following command to view the PHP version.
If the following result is returned, it indicates that PHP has been successfully installed.
PHP 7.4.11 (cli) (built: Sep 29 2020 10:17:06) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies
Run the following command to open the
Press i to switch to the edit mode and modify the
user = apache to
user = nginx and
group = apache to
group = nginx, as shown below.
Press Esc and enter :wq to save and close the file.
Run the following commands in sequence to start PHP-FPM and enable PHP-FPM autostart.
systemctl start php-fpm
systemctl enable php-fpm
Run the following command to create a test file.
This document uses
/usr/share/nginx/htmlthat you configured for your website root directory in Nginx as an example.
echo " phpinfo(); " >> /usr/share/nginx/html/index.php
Enter the following URL in your browser and verify whether the environment has been successfully configured. For more information about how to obtain the public IP address of the instance, see Getting Public IP Addresses.
http://Public IP address of the CVM instance/index.php
If the following appears, the environment has been successfully configured.
After the LNMP environment is built, you can manually build a WordPress website to familiarize yourself with CVM and its features.
If you encounter a problem when using CVM, refer to the following documents for troubleshooting as needed: