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

Setting Up a WordPress Website (Linux)

Application Scenarios

WordPress (WP for short) is initially a blog system and gradually evolved to a free CMS or website setup system. The best practices for ECS guide you through the setup of LNMP on a Linux ECS running the CentOS 7.2 64bit OS and deploy WordPress on the website.

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.

Resources and Costs

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: Set it to 1.
  • Action: Select Allow.
  • Type: Select IPv4.
  • Protocol & Port: Set it to TCP: 80.
  • Source: Set it to 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
  • EIPs

For billing details, see Billing Modes.

Nginx

A high-performance HTTP and reverse proxy server.

Download URL:

http://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.

The price of a domain name is subject to that provided by the domain name registrar. For details, see the help document of the domain name registrar.

Process

The process of manually setting up a WordPress website on a Linux ECS is as follows:
  1. Set up the LNMP environment.
  2. Create a database.
  3. Install WordPress.
  4. Purchase a domain name.
  5. 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 which the target ECS belongs to. For details, see Configuring Security Group Rules.
    Table 2 Security group rules

    Direction

    Priority

    Action

    Type

    Protocol & Port

    Source Address

    Inbound

    1

    Allow

    IPv4

    TCP: 80

    0.0.0.0/0

Procedure

  1. Log in to the ECS.
  2. Set up the LNMP environment. For details, see Manually Deploying LNMP (CentOS 7.2).
  3. 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 the preceding 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 the preceding 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 on 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 creation of 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.

  4. 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 obtained.

    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. Find MySQL configurations in the file and modify them to information in 3.
      Figure 2 Modifying MySQL configurations
    6. Press Esc to exit the editing mode. Then, enter :wq to save the settings and exit the file.
    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 bar of the browser, enter the username or email address and password, and click Log In.

  5. Purchase a domain name.

    Configure a unique domain name for website access. You need to obtain an authorized domain name from the domain name registrar first.

  6. 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 bar of the browser to access the website.