Manually Deploying LNMP (Huawei Cloud EulerOS 2.0)
Overview
The best practices for Huawei Cloud ECS guide you through the deployment of LNMP on a Linux ECS. This section uses the Huawei Cloud EulerOS 2.0 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
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 command to install Nginx:
- Run the following command to check the version of the installed Nginx:
Information similar to the following is displayed:
nginx version: nginx/1.21.5
- Run the following commands to start Nginx and enable it to start automatically upon ECS startup:
systemctl enable nginx
- Run the following command to check the startup status:
systemctl status nginx.service
Information similar to the following is displayed:
- 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 commands in sequence to install MySQL:
cd mysql-server
wget https://repo.huaweicloud.com/hce/2.0/os/x86_64/Packages/mysql-8.0.28-1.hce2.x86_64.rpm
yum install mysql-server
- Run the following commands in sequence to start MySQL and enable it to start automatically upon ECS startup:
systemctl enable mysqld
- Run the following command to check the MySQL status:
systemctl status mysqld.service
Information similar to the following is displayed:
- Run the following command and follow the prompts to harden MySQL:
Securing the MySQL server deployment. Connecting to MySQL using a blank password. 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 There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters SERONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 Please set the password for root here. 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!
- Run the following command to exit the current folder:
- Run the following commands in sequence to install MySQL:
- Install PHP.
- Run the following commands in sequence to install PHP 8:
wget https://repo.huaweicloud.com/hce/2.0/os/x86_64/Packages/php-8.0.0-10.hce2.x86_64.rpm
yum install php-8.0.0-10.hce2.x86_64.rpm
- Run the following command to check the version of the installed PHP:
Information similar to the following is displayed:
- Run the following commands to start PHP and enable it to start automatically upon ECS startup:
systemctl enable php-fpm
- Modify the Nginx configuration file to support PHP.
- Run the following command to open the Nginx configuration file:
- Press i to enter insert mode.
- Modify the nginx.conf file.
Find the server paragraph and configure it as follows:
server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { index index.php index.html index.htm; } location ~ .php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
Figure 2 shows the configuration after modification.
- 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 in sequence to install PHP 8:
- Test the LNMP deployment.
- Create the info.php test file in /usr/share/nginx/html/.
- Run the following command to create and open the info.php test file:
vim /usr/share/nginx/html/info.php
- Press i to enter insert mode.
- Modify the info.php file and add the following to the file:
<?php phpinfo(); ?>
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Run the following command to create and open the info.php test file:
- Enter http://Server IP address/info.php in the address bar. If the following page is displayed, the LNMP environment has been set up.
- Create the info.php test file in /usr/share/nginx/html/.
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