Manually Deploying LNMP (Ubuntu 20.04)
Overview
The best practices for Huawei Cloud ECS guide you through the deployment of LNMP on a Linux ECS. This section uses the Ubuntu 20.04 64bit as an example.
Prerequisites
- The ECS has an EIP bound.
- The rule listed in the following table has been added to the security group which the target ECS belongs to. For details, see Adding a Security Group Rule.
Table 1 Security group rule Direction
Priority
Action
Type
Protocol & Port
Source Address
Inbound
1
Allow
IPv4
TCP: 80
0.0.0.0/0
- The image source has been updated to a Huawei Cloud image source. For details, see How Can I Use an Automated Tool to Configure a Huawei Cloud Image Source (x86_64 and Arm)? This facilitates obtaining and updating the system and software.
Resource Planning
Table 2 lists the resource configuration and software versions used in this practice. The commands and parameters may vary according to the hardware specifications or software versions you would use.
Resource |
Description |
Cost |
---|---|---|
ECS |
|
The following resources generate costs:
For billing details, see Billing Modes. |
Nginx |
A high-performance HTTP and reverse proxy server. |
Free |
MySQL |
An open-source relational database software. |
Free |
PHP |
An open-source software used for web development. |
Free |
Procedure
- Install Nginx.
- Log in to the ECS.
- Run the following commands to install Nginx:
sudo apt-get install nginx
If Do you want to continue? [Y/n] is displayed, enter y or Y to continue the installation.
- (Optional) Configure the firewall.
Uncomplicated Firewall (UFW) is an iptables interface that simplifies the firewall configuration. By default, Ubuntu has UFW installed. Run the following command to check the firewall status:
sudo ufw status
If you do not want to enable the firewall, skip this step. If you want to enable the firewall, run the following command:
sudo ufw enable
Verify that the firewall is enabled.
Before testing Nginx, you need to reconfigure the firewall to allow access to Nginx. Run the following command to automatically register Nginx with UFW:
sudo ufw app list
Information similar to the following is displayed:
Available applications: Nginx Full Nginx HTTP Nginx HTTPS ...
- Nginx Full: Port 80 is enabled to distribute normal and unencrypted web traffic, and port 443 to distribute TLS/SSL-encrypted traffic.
- Nginx HTTP: Port 80 is enabled to distribute normal and unencrypted web traffic.
- Nginx HTTPS: Port 443 is enabled to distribute TLS/SSL-encrypted traffic.
Run the following command to ensure that the firewall allows HTTP and HTTPS connections:
sudo ufw allow 'Nginx Full'
- Verify that Nginx can work properly.
Use the domain name or IP address to access Nginx. The Welcome to nginx page is displayed if Nginx is started normally.
Enter http://IP address of the Nginx server in the address bar to access Nginx. If the following page is displayed, Nginx has been installed.
Figure 1 Accessing Nginx
- Install MySQL.
- Run the following command to install MySQL:
- Check the MySQL status.
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2023-07-26 15:57:29 CST; 22min ago Main PID: 10770 (mysqld) Status: "Server is operational" Tasks: 37 (limit: 4217) Memory: 364.9M CGroup: /system.slice/mysqld.service └─10770 /usr/sbin/mysqld Jul 26 15:57:29 ecs-ubuntu systemd[1]: Starting MySQL Community Server... Jul 26 15:57:29 ecs-ubuntu systemd[1]: Started MySQL Community Server.
- Run the following command to access MySQL:
- Run the following command to set the password for user root:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'xxxxx';
In the preceding command, xxxxx indicates the password you set for user root.
- Run the following command to exit MySQL:
- Run the following command and follow the prompts to harden MySQL:
Securing the MySQL server deployment. Enter password for user root: #Enter the password of user root set in step 4. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y #Press Y to set the password validation policy. There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 #Enter 2 to select the password validation policy. Using existing password for root. Estimated strength of the password: 25 Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y #Press Y to change the password of user root. New password: #Enter a new password of user root. Re-enter new password: #Enter the new password again. Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y #Press Y to confirm the new password. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #Press Y to remove anonymous users. Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #Press Y to disallow remote logins of user root. Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #Press Y to delete the test database and remove access to it. - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #Press Y to reload privilege tables. Success. All done!
- Install PHP.
- Run the following commands to install PHP:
sudo apt install php-fpm
- Run the following command to check the version of the installed PHP:
Information similar to the following is displayed:
PHP 7.4.3-4ubuntu2.19 (cli) (built: Jun 27 2023 15:49:59) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.3-4ubuntu2.19, Copyright (c), by Zend Technologies
- Run the following command to check the runtime status of PHP:
Information similar to the following is displayed:
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2023-07-31 17:33:35 CST; 3min 50s ago Docs: man:php-fpm7.4(8)
If lines 1-16/16 (end) is displayed in the command output, press q to exit.
- Modify the Nginx configuration file to support PHP.
- Run the following command to open the default Nginx configuration file:
- Press i to enter insert mode.
- Modify the opened Nginx configuration file.
In server{}, find the line starting with index and add index.php to this line.
Find location ~ \.php$ {} in server{} and delete the comments from the lines in the following red box:
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Run the following command to reload the Nginx configuration file:
- Run the following commands to install PHP:
- Test the LNMP deployment.
- In the root directory of the Nginx website, create the phpinfo.php file.
sudo vim /var/www/html/phpinfo.php
- Press i to enter insert mode.
- Modify the phpinfo.php file and add the following to the file:
<?php echo phpinfo(); ?>
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Enter http://IP address of the Nginx server/phpinfo.php in the address bar. If the following page is displayed, the LNMP environment has been deployed.
- In the root directory of the Nginx website, create the phpinfo.php file.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot