Manually build WordPress (Linux)

更新时间:
复制 MD 格式

To gain full control over your website environment, manually deploy an LNMP stack and install WordPress to build a flexible blog or web portal.

Prerequisites

  • Enable public access: Assign a static public IP address or bind an Elastic IP Address (EIP) to the ECS instance.

  • Add a security group rule: Allow inbound traffic on TCP ports 22 and 80 in the security group of the instance.

Procedure

This tutorial uses Alibaba Cloud Linux 3 to demonstrate how to deploy WordPress 6.4.4.

Step 1: Deploy the LNMP environment

  1. Log on to an ECS instance.

    1. Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target instance.

    2. Navigate to the details page of the target instance. Click Connect and select Workbench. Follow the on-screen prompts to access the terminal.

  2. Deploy the LNMP environment.

    This installs core components such as Nginx, MySQL, and PHP.

    WordPress depends on specific PHP and MySQL versions. A version mismatch will cause the WordPress installation to fail. For details, see WordPress Compatibility.

Step 2: Create the WordPress database

Create a dedicated database and database user for WordPress.

  1. Log on to MySQL. Use the database password you set during the LNMP deployment.

    mysql -u root -p
  2. Create the database and user, and grant privileges.

    Record the database name, username, and password for later use.

    -- Create a database named wordpress.
    CREATE DATABASE WORDPRESS_DATABASE;
    
    -- Create a dedicated user named wordpress_user and set a password. Use a strong password that is at least 12 characters long and contains uppercase letters, lowercase letters, digits, and special characters.
    CREATE USER 'WORDPRESS_USER'@'localhost' IDENTIFIED BY 'WORDPRESS_PASSWORD';
    
    -- Grant all privileges on the wordpress database to the user.
    GRANT ALL PRIVILEGES ON wordpress.* TO 'WORDPRESS_USER'@'localhost';
    
    -- Flush the privileges to apply the changes.
    FLUSH PRIVILEGES;
    
    -- Exit MySQL.
    EXIT;
    In MySQL 5.7 and later, the password validation plugin is installed by default. Password rules: 8 to 30 characters, and must include uppercase letters, lowercase letters, digits, and special characters. The allowed special characters are ()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/.

Step 3: Download and configure WordPress

  1. Go to the Nginx web root directory and download the Chinese version of WordPress 6.4.4.

    To install the English version of WordPress, replace the URL with https://wordpress.org/wordpress-6.4.4.zip and replace the name of the zip file with wordpress-6.4.4.zip in the following unzip step.
    sudo cd /usr/share/nginx/html
    sudo wget https://cn.wordpress.org/wordpress-6.4.4-zh_CN.zip
  2. Install the unzip command and decompress the WordPress zip file.

    sudo yum install unzip -y
    sudo unzip wordpress-6.4.4-zh_CN.zip
  3. Copy the wp-config-sample.php file to create a wp-config.php file, and keep the original file as a backup.

    cd /usr/share/nginx/html/wordpress
    sudo cp wp-config-sample.php wp-config.php
  4. Edit the configuration file and enter the database information from Step 2, including the database name, username, and password.

    sudo vim wp-config.php

    Press i to enter Insert mode.

    /** The name of the database for WordPress */
    define('DB_NAME', 'WORDPRESS_DATABASE');
    
    /** MySQL database username */
    define('DB_USER', 'WORDPRESS_USER');
    
    /** MySQL database password */
    define('DB_PASSWORD', 'WORDPRESS_PASSWORD');
    
    /** MySQL hostname */
    define('DB_HOST', 'localhost');

    After you finish, press Esc, type :wq, and press Enter to save and exit.

Step 4: Configure Nginx

Modify the default Nginx site configuration so that it can correctly handle PHP requests.

  1. Back up the default configuration and create a new Nginx configuration file.

    sudo mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
    sudo vim /etc/nginx/conf.d/default.conf
  2. Modify the Nginx configuration file.

    Press i to enter Insert mode. In the server and location ~ .php$ blocks, replace the value after root with the WordPress root directory. In this example, the WordPress root directory is /usr/share/nginx/html/wordpress.

    image

    Press Esc, type :wq, and press Enter to save and exit.

  3. Check the configuration syntax.

    If the syntax is ok message appears, restart Nginx.

    sudo nginx -t
    If a syntax error is reported, you can run the sudo mv /etc/nginx/conf.d/default.conf.bak /etc/nginx/conf.d/default.conf command to restore the default configuration.
  4. Restart Nginx for the configuration to take effect.

    sudo systemctl restart nginx

Step 5: Install WordPress and log in

After completing the server configuration, initialize WordPress in your browser.

  1. On your local computer, open a browser and visit http://<Public IP address of the ECS instance> to go to the WordPress installation page.

  2. Fill in the basic information for your website, including the Site Title, administrator User Name, Password, and Your Email, and then click Install WordPress.

  3. After the installation is complete, click Log In and use the username and password that you set in the previous step to log in.

    If you can log in, your WordPress site is up and running. For more information, see the WordPress getting started guide.

Next steps

Manage files via FTP

To upload WordPress themes or plugins via FTP, you need to build an FTP site on Linux.

Set up domain resolution and configure HTTPS

Using an IP address to access a website is unprofessional and insecure. We recommend that you point a domain name to your website and enable HTTPS encryption.

  1. Register a domain name and complete ICP filing

    • If you do not have a domain name, you can register a domain name with Alibaba Cloud.

    • If your domain name points to a website hosted on an Alibaba Cloud server in the Chinese mainland, you must complete an ICP filing.To apply for an ICP filing for the first time, see the ICP filing process. For other scenarios, see the ICP filing process.

  2. Set up domain name resolution

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

  3. Replace the public IP address of the instance with your new domain name.

    1. Connect to the instance and log on 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 HTTPS and encrypt data in transit, protect user privacy, and improve browser trust and SEO rankings.

FAQ

Cannot access WordPress with public IP?

  • Check the security group: Confirm that the instance security group allows inbound traffic on port 80.

  • Check the firewall: Confirm that the OS firewall (such as firewalld) does not block port 80.

  • Check service status: Run sudo systemctl status nginx and sudo systemctl status php-fpm on the ECS instance, and make sure both services are active (running) .

  • Check port listening: Confirm that a service is listening on port 80.

For detailed troubleshooting steps, see Troubleshoot issues when you cannot access services on an ECS instance.

Permalink settings break page access?

To improve how search engines index your site, use static URLs. Before setting permalinks in WordPress, you must add a rewrite rule to your Nginx configuration.

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

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

    Press i to enter Insert mode. In the location / block, add the following line.

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

    Press Esc, type :wq, and press Enter to save and exit.

  2. Restart Nginx to apply the changes.

    sudo systemctl restart nginx

FTP credentials or directory errors during updates?

Insufficient file permissions for the WordPress configuration file, themes, or plugins usually cause this issue. Use the following steps to fix it.

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

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

    Press i to enter Insert mode. At the end of the file, add the following lines.

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

    Press Esc, type :wq, and press Enter to save and exit.

  2. Return to the WordPress dashboard and refresh the page to fix the FTP credentials prompt.

    If the "unable to create directory" issue persists, change the owner of the web root directory to the Nginx user nginx.

    sudo chown -R nginx /usr/share/nginx/html/wordpress

Change the MySQL username and password

  1. Connect to the ECS instance and log on to MySQL.

    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 of the database user.

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

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

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

    FLUSH PRIVILEGES; 
    EXIT;

References