Quick start: Set up WordPress

更新时间:
复制 MD 格式

WordPress is a free, open-source content management system (CMS). You can use it to quickly create and manage various types of websites, including blogs, news sites, e-commerce stores, and social networks. With a vast library of themes and plugins, WordPress makes it easy to customize your site's appearance and functionality. This tutorial shows several methods to quickly set up a WordPress site.

Setup options

This document provides three methods to set up a WordPress site. Choose the one that best fits your needs.

Method

Example operating systems

Description

One-click deployment with ROS

  • Ubuntu 20.04/22.04

  • CentOS 7.7/7.8/7.9

  • Alibaba Cloud Linux 3.2104

Use Resource Orchestration Service (ROS) to automate the deployment of a WordPress site. For more information, see What is Resource Orchestration Service?

Quick setup with a Marketplace image

Alibaba Cloud Linux 3.2104

Note

If you have specific operating system requirements, you can select a Marketplace image with the corresponding operating system.

Alibaba Cloud Marketplace provides WordPress images to quickly set up a WordPress site without deploying a web environment. This method is ideal for users new to building websites with ECS. For more information, see Marketplace.

One-click deployment with Terraform

  • Ubuntu 20.04/22.04

  • CentOS 7.7/7.8/7.9

  • Alibaba Cloud Linux 3.2104

You can use Terraform to automate the deployment of a WordPress site. For more information, see Terraform on Alibaba Cloud.

Procedure

Deploy with ROS (recommended)

  1. Click One-click deployment, configure the parameters as prompted, and then click Deploy Now.

    Key parameters:

    • Region: Select the region where you want to create the ECS instance.

    • Instance source:

      If you have specific requirements for billing, disks, or networking, we recommend that you purchase an ECS instance in advance and then select an existing instance for deployment. For more information, see Create an instance by using the custom launch method.

      Create a new instance

      ROS automatically creates a preemptible instance and deploys WordPress on it. Because preemptible instances do not support ICP filing, create a subscription instance for at least three months if you need this filing. Then, select the existing instance for automatic WordPress deployment.

      • Instance image: Select one of the following images:

        • Ubuntu 20.04/22.04

        • CentOS 7.7/7.8/7.9

        • Alibaba Cloud Linux 3.2104 LTS 64-bit (Recommended)

      • Instance Type: Select an instance type based on your needs. For more information, see Instance families.

      • Instance password: Enter and confirm the password for the ECS instance.

      Select an existing instance

      ROS automatically deploys WordPress on the selected instance. The ECS instance must have public internet access and run one of the following operating systems:

      Note

      If you did not assign a public IP address when you purchased the instance, associate an Elastic IP Address (EIP) with it. For more information, see Associate an EIP.

      • Ubuntu 20.04/22.04

      • CentOS 7.7/7.8/7.9

      • Alibaba Cloud Linux 3.2104

  2. ROS automatically deploys the resources. The deployment is complete when the progress reaches 100%.

    Note

    After deploying WordPress, you can perform the following operations:

    • View created resources: In the ROS console, you can view information about the created resources, such as the ECS instance, VPC, and security group. For more information, see View a stack.

    • Change the MySQL database password: Run the command sudo grep 'temporary password' /var/log/mysqld.log to view and then change the initial password for the root user. For more information, see FAQ.

  3. Click View Deployed Site. You are redirected to the WordPress configuration page.

  4. Fill in the required information, and then click Install WordPress.

    Parameters:

    • Site title: The name of your WordPress site. For example, demowp.

    • User Name: The username for logging in to WordPress. Choose a secure username. For example, testwp.

    • Password: The password for logging in to WordPress. Use a strong password. For example, Wp.123456.

    • Your email: The email address for receiving notifications. For example, username@example.com.

  5. Click Log In. Enter the username testwp and password Wp.123456 that you set during the installation, and then click Log In.

    You are now logged in to your WordPress site. For more information about using WordPress, see the official WordPress documentation.

    After you log in, the WordPress admin Dashboard is displayed. The navigation pane on the left includes menus such as Posts, Media, Pages, Comments, and Appearance, which you can use to start managing your site content.

Use a Marketplace image

The WordPress Platform (ALinux3 LNMP PHP) image used in this example has the following environment:

  • Operating system version: Alibaba Cloud Linux 3.2104

  • Nginx version: 1.26.2

  • PHP version: 8.2

  • MySQL version: 8.0.40

  1. Create an ECS instance from a WordPress image.

    Note
    • If you already have an ECS instance and it does not contain important data, you can change the system image. In the Marketplace Image tab of the Image section, select the WordPress Platform (ALinux3 LNMP PHP) image. For more information, see Change the operating system.

    • If you did not assign a public IP address when you purchased the instance, associate an EIP with it. For more information, see Associate an EIP.

    1. Go to ECS console - custom launch.

    2. On the Custom Launch page, configure settings such as the billing method, region, availability zone, and instance type.

    3. In the Images section, click the Marketplace Images > Go to ECS Marketplace to choose other images (including OS).

    4. Enter WordPress in the search box, click Search, select an image, and then click Use.

      You can click an image title in the search results to go to the image's product page in Marketplace and view its configuration details. The WordPress Platform (ALinux3 LNMP PHP) image used in this example is shown below.

      Note
      • If you have specific operating system requirements, you can select a Marketplace image that meets them.

      • When you choose a Marketplace image, pay attention to its cost. If the image displays ¥0/hr, the image itself is free of charge.

      The WordPress Platform (ALinux3 LNMP PHP) image used in this example includes Alibaba Cloud Linux 3 + Nginx + MySQL + PHP + WordPress. In the search results, click Use to select the image.

      To explore more environments, you can search and filter in Marketplace.

    5. Configure the remaining parameters as prompted.

      Pay attention to the following parameters. For more information about other parameters, see Create an instance by using the custom launch method.

      • Images: The Images section is automatically set to the image you selected.

      • Public IP Address: Select Assign Public IPv4 Address and set a bandwidth value based on your business needs.

  2. Obtain the credentials for WordPress and the MySQL database.

    1. Connect to an ECS instance.

      For more information, see Log on to a Linux instance using Workbench.

    2. Run the following command to view the database credentials.

      sudo cat /root/ReadMe
      ##############################################################
      #         For more information please visit https://weiliu.cn         #
      ##############################################################
      Wordpress admin password: xxx
      MySQL root password: xxx
      
      FTP account: xxx
      FTP password: xxx
      
      Online documentation
      https://weiliu.cn/docs/wordpress/
  3. Add an inbound rule to the security group to allow traffic on port 80. For more information, see Add a security group rule.

    You can also allow traffic on other ports as needed. For example:

    • To connect to the MySQL database remotely, you must allow traffic on the default MySQL port, 3306.

    • To use HTTPS, you must allow traffic on port 443.

  4. Log in to WordPress.

    1. In a web browser, enter http://<Instance-Public-IP>/wp-admin.

      The WordPress login page appears.

    2. Log in to the site with the WordPress credentials you obtained.

      If the following page appears, you have successfully set up your WordPress site. For more information about using WordPress, see the following resources:

      After you log in, the WordPress Dashboard is displayed. The navigation pane on the left includes menus such as Posts, Media, Pages, Comments, and Appearance, which you can use to start managing your site.

Deploy with Terraform

  1. Click One-click deployment to go to Terraform Explorer, where the following Terraform code is automatically loaded.

    Terraform code

    // Instance name
    variable "name" {
      default = "terraform-example"
    }
    
    // Instance type
    variable "instance_type" {
      default = "ecs.e-c1m2.large"
    }
    
    // Instance logon password
    variable "instance_password" {
      default = "Test@12345"
    }
    
    // Region
    variable "region" {
      default = "cn-beijing"
    }
    
    provider "alicloud" {
      region = var.region
    }
    
    variable "create_instance" {
      default = true
    }
    
    // Instance ID
    variable "instance_id" {
      default = ""
    }
    
    // Image ID
    variable "image_id" {
      default = "ubuntu_22_04_x64_20G_alibase_20241224.vhd"
    }
    
    // Create a VPC.
    resource "alicloud_vpc" "vpc" {
      count      = var.create_instance ? 1 : 0
      cidr_block = "192.168.0.0/16"
    }
    
    // Create a VSwitch.
    resource "alicloud_vswitch" "vswitch" {
      count        = var.create_instance ? 1 : 0
      vpc_id       = alicloud_vpc.vpc[0].id
      cidr_block   = "192.168.0.0/16"
      zone_id      = data.alicloud_zones.default.zones.0.id
      vswitch_name = var.name
    }
    
    // Create a security group.
    resource "alicloud_security_group" "group" {
      count               = var.create_instance ? 1 : 0
      security_group_name = var.name
      description         = "foo"
      vpc_id              = alicloud_vpc.vpc[0].id
    }
    
    // Create security group rules (example only; configure rules based on your security policies).
    resource "alicloud_security_group_rule" "allow_all_tcp" {
      count             = var.create_instance ? 1 : 0
      type              = "ingress"                           # Rule type: inbound
      ip_protocol       = "tcp"                               # Protocol type: TCP
      policy            = "accept"                            # Policy: accept
      port_range        = "22/22"                             # Port range: only port 22
      priority          = 1                                   # Priority: 1
      security_group_id = alicloud_security_group.group[0].id # Associate with the previously created security group
      cidr_ip           = "0.0.0.0/0"                         # Allow access from all IP addresses
    }
    
    resource "alicloud_security_group_rule" "allow_tcp_80" {
      count             = var.create_instance ? 1 : 0
      type              = "ingress"
      ip_protocol       = "tcp"
      nic_type          = "intranet"
      policy            = "accept"
      port_range        = "80/80"
      priority          = 1
      security_group_id = alicloud_security_group.group[0].id
      cidr_ip           = "0.0.0.0/0"
    }
    
    resource "alicloud_security_group_rule" "allow_tcp_443" {
      count             = var.create_instance ? 1 : 0
      type              = "ingress"
      ip_protocol       = "tcp"
      nic_type          = "intranet"
      policy            = "accept"
      port_range        = "443/443"
      priority          = 1
      security_group_id = alicloud_security_group.group[0].id
      cidr_ip           = "0.0.0.0/0"
    }
    
    resource "alicloud_security_group_rule" "allow_icmp_all" {
      count             = var.create_instance ? 1 : 0
      type              = "ingress"
      ip_protocol       = "icmp"
      nic_type          = "intranet"
      policy            = "accept"
      port_range        = "-1/-1"
      priority          = 1
      security_group_id = alicloud_security_group.group[0].id
      cidr_ip           = "0.0.0.0/0"
    }
    
    data "alicloud_zones" "default" {
      available_disk_category     = "cloud_essd"
      available_resource_creation = "VSwitch"
      available_instance_type     = var.instance_type
    }
    
    // Create an instance.
    resource "alicloud_instance" "instance" {
      count             = var.create_instance ? 1 : 0
      availability_zone = data.alicloud_zones.default.zones.0.id
      security_groups   = alicloud_security_group.group.*.id
      # series III
      instance_type              = var.instance_type
      system_disk_category       = "cloud_essd"
      system_disk_name           = var.name
      system_disk_description    = "test_foo_system_disk_description"
      image_id                   = var.image_id
      instance_name              = var.name
      vswitch_id                 = alicloud_vswitch.vswitch.0.id
      internet_max_bandwidth_out = 10
      password                   = var.instance_password
    }
    
    resource "alicloud_ecs_command" "command" {
      name            = "DeploydNodejs"
      type            = "RunShellScript"
      command_content = base64encode(local.command_content)
      timeout         = 3600
      working_dir     = "/root"
    }
    
    resource "alicloud_ecs_invocation" "invocation" {
      instance_id = [local.instanceId]
      command_id  = alicloud_ecs_command.command.id
      timeouts {
        create = "10m"
      }
    }
    
    data "alicloud_instances" "default" {
      count = var.create_instance ? 0 : 1
      ids   = [var.instance_id]
    }
    
    locals {
      instanceId         = var.create_instance ? alicloud_instance.instance[0].id : var.instance_id
      instance_public_ip = var.create_instance ? element(alicloud_instance.instance.*.public_ip, 0) : lookup(data.alicloud_instances.default[0].instances.0, "public_ip")
      command_content    = <<SHELL
    #!/bin/bash
    
    if [ -f /etc/os-release ]; then
        source /etc/os-release || { echo "Failed to read the /etc/os-release file"; exit 1; }
    
        if [ -z "$${ID:-}" ] || [ -z "$${VERSION_ID:-}" ]; then
            echo "The /etc/os-release file is not in the expected format or is missing required information"
            exit 1
        fi
    
        OS=$ID
        VER=$VERSION_ID
        echo "Operating system: $OS, Version: $VER"
    else
        echo "Cannot detect the OS version because the /etc/os-release file does not exist"
        exit 1
    fi
    echo "Updating system and installing necessary packages..."
    if [[ $OS == "alinux" ]]; then
    sudo yum update -y
    sudo yum install -y httpd mariadb-server mariadb php php-mysqlnd php-fpm php-xml php-gd
    sudo systemctl start httpd
    sudo systemctl enable httpd
    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    sudo mysql_secure_installation <<EOF
    
    y
    Test@12345
    Test@12345
    y
    y
    y
    y
    EOF
    DB_NAME="wordpress"
    DB_USER="wordpressuser"
    DB_PASSWORD="Test@12345" # Replace with your actual password.
    mysql -u root -pTest@12345 <<EOF
    CREATE DATABASE wordpress;
    CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'Test@12345';
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
    FLUSH PRIVILEGES;
    EOF
    cd /var/www/html
    sudo wget https://wordpress.org/latest.tar.gz
    sudo tar -xzvf latest.tar.gz
    sudo rm latest.tar.gz
    sudo chown -R apache:apache /var/www/html/wordpress
    sudo chmod -R 755 /var/www/html/wordpress
    sudo cat <<'EOF' > /etc/httpd/conf.d/wordpress.conf
    <VirtualHost *:80>
        ServerAdmin webmaster@yourdomain.com
        DocumentRoot "/var/www/html/wordpress"
        ServerName yourdomain.com
        ServerAlias www.yourdomain.com
        <Directory "/var/www/html/wordpress">
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
        ErrorLog "/var/log/httpd/wordpress-error.log"
        CustomLog "/var/log/httpd/wordpress-access.log" combined
    </VirtualHost>
    EOF
    
    sudo systemctl restart httpd
    elif [[ $OS == "centos" ]]; then
          yum -y update
          yum -y install epel-release
          if [[ $VER == "7" ]]; then
          yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm  # For CentOS 7
          elif [[ $VER == "8" ]]; then
          yum -y install http://rpms.remirepo.net/enterprise/remi-release-8.rpm  # For CentOS 8
           else
            echo "Unsupported CentOS version"
            exit 1
          fi
          yum-config-manager --enable remi-php80
          yum -y install httpd mariadb-server mariadb php php-mysqlnd php-fpm
          systemctl start httpd
          systemctl enable httpd
          systemctl start mariadb
          systemctl enable mariadb
          echo "CREATE DATABASE wordpress;" | mysql -u root
          echo "CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'Test@12345';" | mysql -u root
          echo "GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';" | mysql -u root
          echo "FLUSH PRIVILEGES;" | mysql -u root
          cd /var/www/html
          curl -O https://wordpress.org/latest.tar.gz
          tar -xzvf latest.tar.gz
          rm latest.tar.gz
          chown -R apache:apache /var/www/html/wordpress
          chmod -R 755 /var/www/html/wordpress
    cat << 'EOF' > /etc/httpd/conf.d/wordpress.conf
    <VirtualHost *:80>
        ServerAdmin admin@example.com
        DocumentRoot "/var/www/html/wordpress"
        ServerName your_domain_or_IP
        ErrorLog "/var/log/httpd/wordpress-error.log"
        CustomLog "/var/log/httpd/wordpress-access.log" combined
    
        <Directory "/var/www/html/wordpress">
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    EOF
          systemctl restart httpd
    elif [[ $OS == "ubuntu" ]]; then
    # Update the system and install necessary packages.
    sudo apt update
    sudo apt install -y apache2 mariadb-server php libapache2-mod-php php-mysql php-xml php-gd
    sudo systemctl start apache2
    sudo systemctl enable apache2
    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    sudo mysql_secure_installation <<EOF
    
    y
    Test@12345
    Test@12345
    y
    y
    y
    y
    EOF
    DB_NAME="wordpress"
    DB_USER="wordpressuser"
    DB_PASSWORD="Test@12345"
    mysql -u root -pTest@12345 <<EOF
    CREATE DATABASE $DB_NAME;
    CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASSWORD';
    GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost';
    FLUSH PRIVILEGES;
    EOF
    cd /var/www/html
    sudo wget https://wordpress.org/latest.tar.gz
    sudo tar -xzvf latest.tar.gz
    sudo rm latest.tar.gz
    sudo chown -R www-data:www-data /var/www/html/wordpress
    sudo chmod -R 755 /var/www/html/wordpress
    sudo cat <<'EOF' > /etc/apache2/sites-available/wordpress.conf
    <VirtualHost *:80>
        ServerAdmin webmaster@yourdomain.com
        DocumentRoot "/var/www/html/wordpress"
        ServerName yourdomain.com
        ServerAlias www.yourdomain.com
        <Directory "/var/www/html/wordpress">
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
        ErrorLog $${APACHE_LOG_DIR}/wordpress-error.log
        CustomLog $${APACHE_LOG_DIR}/wordpress-access.log combined
    </VirtualHost>
    EOF
    sudo a2ensite wordpress.conf
    sudo a2dissite 000-default.conf
    sudo systemctl restart apache2
    fi
    
      SHELL
    }
    
    output "instance_public_ip" {
      value = "${local.instance_public_ip}"
    }
    
    output "ecs_login_address" {
      value = "https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs&regionId=${var.region}&instanceId=${local.instanceId}"
    }
  2. Modify the parameters based on your needs. By default, a VPC and a pay-as-you-go ECS instance with an Ubuntu operating system are created in the China (Beijing) region. For more information about ECS billing, see Billing overview.

  3. Click Start Debugging to preview the resources to be created. If the resource details are correct, click Preview and Execute to start creating the resources. The deployment is complete when the execution status shows Succeeded.

  4. Verify the deployment.

    1. In a web browser, enter the following address. Replace <instance_public_ip> with the IP address from the Terraform output.

      http://<instance_public_ip>
    2. Fill in the basic website information, and then click Install WordPress.

      Parameters:

      • Site title: The name of your WordPress site. For example, wordpress.

      • User Name: The username for logging in to WordPress. Choose a secure username. For example, wordpressuser.

      • Password: The password for logging in to WordPress. Use a strong password. For example, Test@12345.

      • Your email: The email address for receiving notifications. For example, username@example.com.

    3. Click Log In.

    4. Enter the username wordpressuser and password Test@12345 that you set during the installation, and then click Log In.

      You are now logged in to your WordPress site. For more information about using WordPress, see the official WordPress documentation.

Related operations

Domain resolution and HTTPS

Accessing a site by its IP address is insecure and unprofessional. We recommend that you associate a domain name with your site and enable HTTPS encryption.

  1. Register a domain name and complete ICP filing

  2. Configure DNS resolution

    Resolve your domain name to the public IP address of your ECS instance.

  3. Replace the instance's public IP address with the new domain name.

    1. Connect to the instance remotely and log in to the MySQL database.

      mysql -u root -p
    2. Switch to the WordPress database and set the domain name.

      Replace public_ip with the instance's public IP address and domain with your domain name.

      use wordpress;
      UPDATE wp_options SET option_value = replace(option_value, 'http://PUBLIC_IP', 'http://DOMAIN') where option_name = 'home' OR option_name = 'siteurl';
      EXIT;
  4. Configure an SSL certificate (HTTPS) 

    Deploy an SSL certificate to enable encrypted data transmission with HTTPS. This protects user privacy and improves browser trust and SEO rankings.

FAQ

Cannot access WordPress with the public IP

  • Check the security group: Make sure the instance's security group allows inbound traffic on port 80.

  • Check the firewall: Make sure the operating system's internal firewall (such as firewalld) is not blocking port 80.

  • Check service status: On the ECS instance, run sudo systemctl status nginx and sudo systemctl status php-fpm to ensure the services are in the active (running) state.

  • Check port listening: Verify that port 80 is being listened on.

For detailed troubleshooting steps, see Troubleshoot access failures to services in an ECS instance.

Cannot access pages with permalinks

Using static-like page URLs can improve your site's search engine optimization. Before setting permalinks in WordPress, you must configure rewrite rules in Nginx.

  1. Connect to the instance remotely and open the Nginx configuration file.

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

    Press the i key to enter edit mode and add the following code inside the location / block.

    try_files $uri $uri/ /index.php?$args;

    Press the Esc key, enter :wq, and then press the Enter key to save and exit the file.

  2. Restart the Nginx service for the changes to take effect.

    sudo systemctl restart nginx

Troubleshoot update and upload errors

This issue is often caused by incorrect file permissions for the WordPress configuration, themes, or plugins. Follow these steps to resolve it.

  1. Log in to the ECS instance and open the WordPress configuration file.

    sudo vim /usr/share/nginx/html/wordpress/wp-config.php

    Press the i key to enter edit mode and add the following code at the end of the file.

    define("FS_METHOD","direct");
    define("FS_CHMOD_DIR", 0777);
    define("FS_CHMOD_FILE", 0777);

    Press the Esc key, enter :wq, and then press the Enter key to save and exit the file.

  2. Return to the WordPress Dashboard and refresh the page. The issue with FTP credentials should now be resolved.

    If the "cannot create directory" error persists, change the ownership of the website's root directory to the Nginx user, nginx.

    sudo chown -R nginx /usr/share/nginx/html/wordpress
  3. If the issue persists after the steps above, PHP-FPM may be running as a different user than Nginx. Run the following command to check the current PHP-FPM user:

    grep -E '^user|^group' /etc/php-fpm.d/www.conf

    If the output shows user = apache and group = apache, change them to nginx and restart the PHP-FPM service:

    sudo sed -i 's/^user = apache/user = nginx/; s/^group = apache/group = nginx/' /etc/php-fpm.d/www.conf
    sudo systemctl restart php-fpm

Change default MySQL credentials

  1. Connect to the ECS instance remotely and log in to the MySQL database.

    mysql -u root -p
  2. Switch to the mysql database and view the usernames.

    use mysql;
    select user from mysql.user;
  3. Change the database username and password.

    • Change the database username to a new username.

      UPDATE user SET user='NEW_USER_NAME' WHERE user='USER_NAME';

      For example, to change the username from root to admin:

      UPDATE mysql.user SET user='admin' WHERE user='root';
    • Change the password for the database user.

      ALTER USER 'USER_NAME'@'localhost' IDENTIFIED BY 'PASSWORD'

      For example, to change the password for the root user to Password@2025!:

      ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password@2025!';
  4. Flush the privileges to apply the changes and exit the MySQL database.

    FLUSH PRIVILEGES; 
    EXIT;

Related documents