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.
Note: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.
nginx -v
If the following result is returned, it indicates that Nginx has been successfully installed.
nginx version: nginx/1.18.0
cat /etc/nginx/nginx.conf
The /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.
cd /etc/nginx/conf.d
cp default.conf default.conf.bak
default.conf
file.vim default.conf
default.conf
file.index
under location
, as shown below:#
of location ~ \\.php$
and modify the following configuration items:root
to your website root directory. This document uses /usr/share/nginx/html;
as an example.fastcgi_pass
to unix:/run/php-fpm/www.sock;
. This configuration should be the same as listen
in the /etc/php-fpm.d/www.conf
file, because Nginx is associated with PHP-FPM through UNIX sockets./scripts$fastcgi_script_name;
after fastcgi_param SCRIPT_FILENAME
with $document_root$fastcgi_script_name;
.systemctl start nginx
systemctl enable nginx
Run the following command to install MySQL.
dnf -y install @mysql
Run the following command to view the MySQL version.
mysql -V
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
mysql_secure_installation
Perform the following steps:
y
and press Enter to start configurations.2
and press Enter.y
to confirm the password.y
and press Enter to remove anonymous users.y
and press Enter.n
and press Enter.y
and press Enter to delete the test library and access permission to it.y
and press Enter to reload the authorization table.dnf -y install epel-release
dnf update epel-release
dnf clean all
dnf makecache
Run the following command to install the REMI repository.
Note: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.
php -v
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 www.conf
file.
vi /etc/php-fpm.d/www.conf
Press i to switch to the edit mode and modify the www.conf
file.
Change 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.
Note:This document uses
/usr/share/nginx/html
that you configured for your website root directory in Nginx as an example.
echo "<?php 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:
Was this page helpful?