Updated on 2025-08-06 GMT+08:00

Setting Up a WordPress Website (Linux)

Scenarios

WordPress is initially a blog system and gradually evolved to a free CMS or website setup system. This section guides you through the setup of LNMP on a Linux ECS running the CentOS 7.2 64-bit OS and deployment of WordPress on the website.

Video

Solution Architecture

Figure 1 Setting up a WordPress website (Linux)

Advantages

  • A website with a simple networking architecture can be quickly set up.
  • The website is secure and easy to use.

Resource Planning

Table 1 Resources and costs

Resource

Description

Cost

VPC

VPC CIDR block: 192.168.0.0/16

Free

VPC subnet

  • AZ: AZ1
  • CIDR block: 192.168.0.0/24

Free

Security group

Inbound rule:

  • Priority: 1
  • Action: Allow
  • Type: IPv4
  • Protocol & Port: TCP:80
  • Source: 0.0.0.0/0

Free

ECS

  • Billing mode: Yearly/Monthly
  • AZ: AZ1
  • Flavor: s6.large.4
  • Image: CentOS 7.2 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
  • EIP

For billing details, see Billing Modes.

Nginx

A high-performance HTTP and reverse proxy web server.

Download URL:

https://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Free

MySQL

An open-source relational database software

Download URL:

https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm

Free

PHP

An open-source software used for web development

Download URL:

https://mirrors.huaweicloud.com/remi/enterprise/remi-release-7.rpm

Free

WordPress

An open-source blogging software.

Download URL:

https://wordpress.org/download/releases/

Free

Domain name

Used to access the created website.

Consult the domain name registrar for the price of the domain name. You can also check the domain name price from the documentation of the domain name registrar.

Process

The process of manually setting up a WordPress website on a Linux ECS is as follows:
  1. Install Nginx.
  2. Install MySQL.
  3. Install PHP.
  4. Create a database.
  5. Install WordPress.
  6. Purchase a domain name.
  7. Configure DNS records.

Procedure

Preparations

  • A VPC and an EIP are available.
  • A domain name is available if you plan to configure a domain name for the website.
  • The rule listed in Table 2 has been added to the security group that the target ECS belongs to. For details, see Configuring Security Group Rules.
    Table 2 Security group rule

    Direction

    Priority

    Action

    Type

    Protocol & Port

    Source

    Inbound

    1

    Allow

    IPv4

    TCP: 80

    0.0.0.0/0

Procedure

  • WordPress setup commands differ by OS . Choose the proper commands for your ECS based on the OS running on it to ensure successful installation. This document shows how to set up WordPress 6.6.1 on CentOS 7.2.
  • WordPress must match the versions of PHP and MySQL. Otherwise, WordPress installation will fail. For details about the mapping, see WordPress Compatibility.
  1. Log in to the ECS.
  2. Install Nginx.

    1. Log in to the ECS.
    2. Run the following command to download the Nginx package:
      wget https://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    3. Run the following command to create the Nginx yum repository:
      rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
    4. Run the following command to install Nginx:
      yum -y install nginx
    5. Run the following command to check the Nginx version:
      nginx -v

      Information similar to the following is displayed:

      nginx version: nginx/1.26.1
    6. Run the following commands to start Nginx and enable it to start automatically upon ECS startup:
      systemctl start nginx
      systemctl enable nginx
    7. Run the following command to check the startup status:
      systemctl status nginx.service

      Information similar to the following is displayed:

    8. 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 2 Accessing Nginx

  3. Install MySQL.

    1. Run the following commands in sequence to install MySQL:
      rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm
      yum -y install mysql-community-server
    2. Run the following command to check the MySQL version:
      mysql -V

      Information similar to the following is displayed:

      mysql  Ver 8.0.42 for Linux on x86_64 (MySQL Community Server - GPL)
    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. Run the following command to check the MySQL status:
      systemctl status mysqld.service

      Information similar to the following is displayed.

    5. Run the following command to obtain the root user's password that was automatically set during MySQL installation:
      grep 'temporary password' /var/log/mysqld.log
      Information similar to the following is displayed:
      2018-08-29T07:27:37.541944Z 1 [Note] A temporary password is generated for root@localhost: 2YY?3uHUA?Ys
    6. Run the following command and follow the prompts to harden MySQL:
      mysql_secure_installation
      Securing the MySQL server deployment.
      
      Enter password for user root:    #Enter the obtained password of user root.
      The existing password for the user account root has expired. Please set a new password.
      
      New password:  #Enter a new password of user root.
      
      Re-enter new password:   #Enter the new password again.
      The 'validate_password' plugin is installed on the server.
      The subsequent steps will run with the existing configuration of the plugin.
      Using existing password for root.
      
      Estimated strength of the password: 100
      Change the password for root ? ((Press y|Y for Yes, any other key for No) : N   #Press N.
      
       ... skipping.
      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!

  4. Install PHP.

    1. Run the following commands to install the EPEL and REMI repositories:
      yum install -y epel-release
      rpm -Uvh https://mirrors.huaweicloud.com/remi/enterprise/remi-release-7.rpm
    2. Run the following command to install the Yum repository management tool:
      yum -y install yum-utils
    3. Run the following command to enable the PHP 8.0 repository:
      yum-config-manager --enable remi-php80
    4. Run the following commands to install PHP:
      yum install -y php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json
    5. Run the following command to check the version of the installed PHP:
      php -v

      If information similar to the following is displayed, PHP has been installed:

    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 3 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 insert mode.
      5. Modify the default.conf file.

        Find the server paragraph and configure it as follows:

        • Add index.php to the index configuration line of location.
              location / {
                  root   /usr/share/nginx/html;
                  index  index.html index.htm index.php;  
              }
        • Add the following configuration:
              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 4 shows the configuration after modification.

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

  5. Create a database.

    1. Run the following command and enter the root user password of MySQL as prompted to log in to the MySQL CLI:
      mysql -u root -p
    2. Run the following command to create a database:
      CREATE DATABASE wordpress;

      In this command, wordpress is the database name, which can be customized.

    3. Run the following command to create a user:
      CREATE USER 'user'@'localhost' IDENTIFIED BY 'xxxxx';

      In this command, user is the name of the database user, and xxxxx is the configurable user password.

    4. Run the following command to grant all permissions for the WordPress database to the user:
      GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost';
    5. Run the following command to make all configurations take effect:
      FLUSH PRIVILEGES;
    6. Run the following command to exit the MySQL CLI:
      exit
    7. (Optional) Run the following commands to verify the database and user and then exit the MySQL CLI:
      mysql -u user -p
      SHOW DATABASES;
      exit

      In the preceding command, user is the created username for logging in to the database.

  6. Install WordPress.

    1. Run the following commands to go to the root directory of the Nginx website and download the WordPress package:
      cd /usr/share/nginx/html
      wget https://cn.wordpress.org/wordpress-6.6.1-zh_CN.tar.gz
    2. Run the following command to decompress the WordPress software package:
      tar zxvf wordpress-6.6.1-zh_CN.tar.gz

      After the decompression, the folder wordpress is generated.

    3. Run the following commands to go to the WordPress installation directory, copy the wp-config-sample.php file to the wp-config.php file, and retain the original sample configuration file as a backup:
      cd /usr/share/nginx/html/wordpress
      cp wp-config-sample.php wp-config.php
    4. Run the following command to open and edit the created configuration file:
      vim wp-config.php
    5. Press i to enter insert mode. Locate the MySQL parameters in the file and modify them according to step 5.
      Figure 5 Modifying MySQL configurations
    6. Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
    7. Enter http://Server IP address/wordpress in the address bar of the browser to access the installation wizard.
    8. Set the site title, administrator username, password, and email address. Then, click Install WordPress.
      Table 3 Configuration parameters

      Parameter

      Description

      Site title

      Name of the WordPress website.

      Username

      Name of the WordPress administrator.

      Password

      Default or user-defined password.

      Do not reuse an existing password and keep your password secure.

      Email address

      Email address for receiving notifications.

    9. Check that the installation is successful.
    10. Click Log In. Alternatively, enter http://Server IP address/wordpress/wp-login.php in the address box of the browser, enter the username or email address and password, and click Log In.

  7. Purchase a domain name.

    Obtain an authorized domain name from the domain name registrar and configure the unique domain name for website access.

  8. Configure DNS records.

    Your website can be visited using the registered domain name only after DNS records are configured. For details, see Routing Internet Traffic to a Website.

    For example, if the domain name is www.example.com, enter http://www.example.com in the address box of the browser to access the website.