Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Manually Deploying LNMP (CentOS 8.0)

Updated on 2024-11-04 GMT+08:00

Overview

LNMP (Linux, Nginx, MySQL, and PHP) is one of the mainstream website server architectures. It is used for running large-sized and high-concurrency website applications, such as e-commerce websites, social networks, and content management systems. This section describes how to use a CentOS 8.0 64bit Linux ECS to set up the LNMP environment on Huaei Cloud.

Prerequisites

  1. The ECS has an EIP bound.
  2. 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 rules

    Direction

    Priority

    Action

    Type

    Protocol & Port

    Source Address

    Inbound

    1

    Allow

    IPv4

    TCP: 80

    0.0.0.0/0

  3. To obtain and update the system and software, you are advised to update the image source 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)?

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.

Table 2 Resources and costs

Resource

Description

Cost

ECS

  • Billing mode: pay-per-use
  • AZ: AZ1
  • Flavor: s6.large.4
  • Image: CentOS 8.0 64bit
  • System disk: 40 GiB
  • EIP: Auto assign
  • EIP type: Dynamic BGP
  • Billed by: Traffic
  • Bandwidth: 5 Mbit/s

The following resources generate costs:

  • ECSs
  • EVS disks
  • EIPs

For billing details, see Billing Modes.

Nginx

A high-performance HTTP and reverse proxy server.

Example: Nginx 1.20.1

Free

MySQL

An open-source relational database software

Example: MySQL 8.0.26

Free

PHP

An open-source software used for web development

Example: PHP 7.4.19

Free

Procedure

  1. Install Nginx.

    1. Log in to the ECS.
    2. Run the following command to install Nginx:

      sudo dnf -y install https://nginx.org/packages/centos/8/x86_64/RPMS/nginx-1.20.1-1.el8.ngx.x86_64.rpm

    3. Run the following command to check the Nginx version:

      nginx -v

      Information similar to the following is displayed:

      nginx version: nginx/1.20.1
    4. Run the following commands to start Nginx and enable it to start automatically upon ECS startup:

      systemctl start nginx

      systemctl enable nginx

    5. Run the following command to check the startup status:

      systemctl status nginx.service

      Information similar to the following is displayed.

    6. 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

  2. Install MySQL.

    1. Run the following command to install MySQL:

      sudo dnf -y install @mysql

    2. Run the following command to check the MySQL version:

      mysql -V

      Information similar to the following is displayed:

      mysql  Ver 8.0.26 for Linux on x86_64 (Source distribution)
    3. Run the following commands in sequence to start MySQL and enable it to start automatically upon ECS startup:

      systemctl start mysqld

      systemctl enable mysqld

    4. Check the MySQL status.

      systemctl status mysqld.service

      Information similar to the following is displayed.

    5. Run the following command and follow the prompts to harden MySQL:

      mysql_secure_installation

      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    #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.
      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!

  3. Install PHP.

    1. Run the following commands to add and update the EPEL repository:

      sudo dnf -y install epel-release

      sudo dnf -y update epel-release

    2. Run the following commands to delete unnecessary software packages from the cache and update the software repository:

      sudo dnf clean all

      sudo dnf makecache

    3. Run the following command to start the PHP 7.4 module:

      dnf module enable php:7.4

    4. Run the following command to install the required PHP module:

      sudo dnf -y 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

    5. Run the following command to check the version of the installed PHP:

      php -v

      Information similar to the following is displayed.

    6. Run the following commands to start PHP and enable it to start automatically upon ECS startup:

      systemctl start php-fpm

      systemctl enable php-fpm

    7. Modify the Nginx configuration file to support PHP.
      1. Run the following command to open the /etc/nginx/nginx.conf file:

        vim /etc/nginx/nginx.conf

        Figure 2 nginx.conf

        According to the nginx.conf, the configuration file is directed to /etc/nginx/conf.d/*.conf.

      2. Enter :quit to exit nginx.conf.
      3. Run the following command to open the /etc/nginx/conf.d/default.conf file:

        vim /etc/nginx/conf.d/default.conf

      4. Press i to enter the editing mode.
      5. Modify the default.conf file.
        Find the server paragraph and configure it as follows:
            server {
                listen       80;
                server_name  localhost;
        
                #access_log /var/log/nginx/host.access.log  main;
        
            location / {
                root   /usr/share/nginx/html;
                index  index.html index.htm index.php;    
            }
        
            location ~ \.php$ {
                root           /usr/share/nginx/html;
                fastcgi_pass   unix:/run/php-fpm/www.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
          }

        Figure 3 shows the configuration after modification.

        Figure 3 Configuration after modification
      6. Press Esc to exit the editing mode. Then, enter :wq to save the settings and exit the file.
    8. Run the following command to reload the Nginx configuration file:

      service nginx reload

  4. Test the LNMP deployment.

    1. Create the info.php test file in /usr/share/nginx/html/.
      1. Run the following command to create and open the info.php test file:

        vim /usr/share/nginx/html/info.php

      2. Press i to enter the editing mode.
      3. Modify the info.php file and add the following to the file:
        <?php
         phpinfo();
        ?>
      4. Press Esc to exit the editing mode. Then, enter :wq to save the settings and exit the file.
    2. Enter http://Server IP address/info.php in the address bar. If the following page is displayed, the environment has been set up.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback