WordPress is a free, open-source content management system (CMS) that allows you to easily create and manage websites, including blogs, news websites, e-commerce websites, and social media websites. WordPress has a rich library of themes and plug-ins that allows you to customize the appearance and functionality of your websites. This topic describes how to build a WordPress website on Elastic Compute Service (ECS) instances that run different Linux operating systems.
Preparations
To build a WordPress website on an existing Linux ECS instance, make sure that the instance meets the following requirements:
A public IP address is automatically assigned to the ECS instance. Alternatively, an elastic IP address (EIP) is associated with the ECS instance. For instructions on how to enable public bandwidth, see Enable public bandwidth.
Inbound rules are added to a security group of the Linux ECS instance to open ports 22 and 80. For information about how to add a security group rule, see Add a security group rule.
Important
For security reasons, only ports that are required to deploy and test the LNMP stack and the WordPress website are open. LNMP is the acronym for the names of the following open source components: Linux operating system, NGINX web server, MySQL relational database management system, and PHP programming language. You can open other ports based on your business requirements. For example, if you want to connect to a MySQL database that is deployed on an ECS instance, you must add an inbound rule to a security group of the instance to open port 3306, which is the default port for MySQL.
Procedure
Warning
The commands that you must use to build a WordPress website on a Linux ECS instance may vary based on the operating system of the instance. Use the commands that are suitable for the operating system of your Linux ECS instance. Otherwise, you may be unable to build the WordPress website. In this topic, ECS instances that run Alibaba Cloud Linux 2, Alibaba Cloud Linux 3, CentOS 7, and CentOS 8 are used to deploy WordPress 6.4.
Deploy an LNMP stack. For more information, see Deploy an LNMP stack.
Important
For information about the methods for deploying an LNMP stack, see Deploy an LNMP stack. Each WordPress version requires specific PHP and MySQL versions. If the PHP or MySQL version is incompatible with the WordPress version that you want to install, WordPress may fail to be installed. For information about PHP and MySQL versions that are compatible with each WordPress version, see WordPress Compatibility.
In this topic, NGINX is used, which is a web server. If Apache is installed on your Linux ECS instance, WordPress is inaccessible because port 80 is used by Apache.
Connect to an ECS instance.
For more information, see Use Workbench to connect to a Linux instance over SSH.
Configure a database for WordPress.
Log on to MySQL.
Note
Use the root
user and enter the password of the user to log on to MySQL. The password is the password you configured for MySQL when you built the LNMP stack.
Create a database named wordpress
for the WordPress website that you want to build.
create database wordpress;
Create a user named user
to manage the wordpress database and set the password of the user to PASSword123.
to increase data security.
create user 'user'@'localhost' identified by 'PASSword123.';
Note
You can run the show variables like "%password%";
command to query the MySQL password strength rules. In this example, the following strength rules apply to MySQL passwords: The password must be 8 to 30 characters in length and contain uppercase letters, lowercase letters, digits, and special characters. Supported special characters include ( ) ` ~ ! @ # $ % ^ & * - + = | { } [ ] : ; ‘ < > , . ? /
By default, the validate_password plug-in is installed in MySQL 5.7 and later versions to validate the strength of passwords.
Grant the user named user all permissions on the wordpress
database.
grant all privileges on wordpress.* to 'user'@'localhost';
Apply the preceding settings.
Exit MySQL.
Download WordPress and save it to the root directory of the website that you want to build.
Go to the root directory of the NGINX website and download the WordPress package.
Note
In the example, the Chinese version of WordPress is installed by default. To install the English version of WordPress, run the wget https://wordpress.org/wordpress-6.4.4.zip
command to download the package for the English version of WordPress. Replace wordpress-6.4.4-zh_CN.zip with wordpress-6.4.4.zip
in commands used in subsequent steps.
cd /usr/share/nginx/html
sudo wget https://cn.wordpress.org/wordpress-6.4.4-zh_CN.zip
(Optional) Install the unzip
command.
Run the following command in Alibaba Cloud Linux 2, Alibaba Cloud Linux 3, CentOS 7, or CentOS 8:
sudo yum install unzip -y
Run the following command in Ubuntu 20.04 or later:
sudo apt install unzip -y
Decompress the WordPress package.
sudo unzip wordpress-6.4.4-zh_CN.zip
Copy the content of the wp-config-sample.php
file in the WordPress installation directory to the wp-config.php
file and use the wp-config-sample.php
file as a backup.
cd /usr/share/nginx/html/wordpress
sudo cp wp-config-sample.php wp-config.php
Modify the configuration file of WordPress.
Open the wp-config.php
file.
Press the I
key to enter Insert mode.
Modify the MySQL-related settings based on the configured database for WordPress as shown in the following code snippet.
Note
The name of the database for WordPress, MySQL database username, and MySQL database password that you specify in the WordPress configuration file must be the same as those that you configure in the Configure a database for WordPress step.
// ** MySQL settings - Obtain the information from your host. ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** The MySQL database username */
define('DB_USER', 'user');
/** The MySQL database password */
define('DB_PASSWORD', 'PASSword123.');
/** The MySQL hostname */
define('DB_HOST', 'localhost');
Note
The data of the WordPress website is stored by the user named user
in the wordpress
database.
Press the Esc
key to exit Insert mode. Enter :wq
and press the Enter
key to save and close the configuration file.
Modify the NGINX configuration file.
Run the following command to open the NGINX configuration file:
sudo vi /etc/nginx/conf.d/default.conf
Press the I
key to enter Insert mode and modify the configuration file.
Alibaba Cloud Linux 2, Alibaba Cloud Linux 3, CentOS 7, or CentOS 8
Ubuntu 20.04 or later
Within the server
braces, replace the content after root
with the root directory of the WordPress website.
In this example, the root directory of the WordPress website is /usr/share/nginx/html/wordpress
.
Within the location ~ .php$
braces, replace the content that follows root
with the root directory of the WordPress website.
Note
When you replace the content with the root directory of the WordPress website, append a semicolon (;
) to the root directory. Otherwise, NGINX cannot be restarted.
In this example, the php-fpm
listens on the /run/php-fpm/www.sock
address. Refer to the actual display for details.

Within the server
braces, replace the content after root
with the root directory of the WordPress website.
In this example, the root directory of the WordPress website is /usr/share/nginx/html/wordpress
.
Within the location ~ .php$
braces, replace the content that follows root
with the root directory of the WordPress website.
Note
When you replace the content with the root directory of the WordPress website, append a semicolon (;
) to the root directory. Otherwise, NGINX cannot be restarted.
In this example, the php-fpm
listens on the /run/php/php8.4-fpm/www.sock
address. Refer to the actual display for details.

Press the Esc
key to exit Insert mode. Enter :wq
and press the Enter
key to save and close the configuration file.
Run the following command to restart NGINX:
sudo systemctl restart nginx
Install WordPress and log on to the WordPress website.
On your on-premises computer, use a web browser to access http://<Public IP address of the ECS instance>
to go to the WordPress installation page.
Configure basic information about the WordPress website and click Run the installation.
Configure the following parameters:
Site Title: the name of the WordPress website. Example: demowp.
Username: the username that you want to use to log on to WordPress. Make sure that the username is secure. Example: testwp.
Password: the password that you want to use to log on to WordPress. We recommend that you specify a strong password. Example: Wp.123456.
Your Email: the email address that you want to use to receive notifications. Example: username@example.com.
Click Install Wordpress.
Enter the testwp
username and the Wp.123456
password that you specified when you installed WordPress, and click LOGIN.
You are logged on to your WordPress website. For more information about how to use WordPress, see the WordPress documentation.
Related operations
Configure a domain name for the WordPress website
If you allow users to access the WordPress website by using the public IP address of the ECS instance on which the WordPress website is built, the security of the instance is compromised. To improve security, configure a domain name for the WordPress website. If you have a domain name or want to register a domain name for the WordPress website, perform the following steps:
Register a domain name.
You can register a domain name on Alibaba Cloud. For more information, see Register a domain name on Alibaba Cloud.
Apply for an Internet Content Provider (ICP) filing for the domain name.
If the WordPress website is built on an ECS instance that is located in a region inside the Chinese mainland, apply for an ICP filing for the domain name before you use the domain name for the WordPress website. For more information, see ICP filing process.
Note
You can apply for an ICP filing for the domain name of a website hosted on an ECS instance only if the instance is a subscription instance that has a subscription duration of at least three months. If the ECS instance on which the WordPress website is built does not meet the preceding requirements, perform one of the following operations:
The entire ICP filing process requires 1 to 22 business days to complete. The actual amount of time required may vary.
For the frequently asked questions about the ICP filing process, see FAQ.
Resolve the registered domain name
to the public IP address of the ECS instance. For more information, see Get Started.
Replace the public IP address of the ECS instance with the registered domain name.
Connect to the ECS instance on which the WordPress website is built.
For more information, see Overview of ECS Remote Connection Methods.
Log on to MySQL.
Switch to the database for WordPress.
Configure the registered domain name for the WordPress website.
Note
Replace the following variables in the command with actual values:
http://<Public IP address of the ECS instance>: Replace <Public IP address of the ECS instance> with the actual public IP address of the ECS instance on which the WordPress website is built.
http://www.example.com: Replace this domain name with the registered domain name for the WordPress website.
update wp_options set option_value = replace(option_value, 'http://<Public IP address of the instance>', 'http://www.example.com') where option_name = 'home' OR option_name = 'siteurl';
Exit MySQL.
The registered domain name is configured for your WordPress website.
FAQ
Q1: Why am I unable to access the WordPress website by using the public IP address of the ECS instance on which the WordPress website is hosted?
Possible causes and solutions:
Port 80 is not open in the security groups of the ECS instance, the system firewall is enabled on the ECS instance, or port 80 is used by a different service.
For information about how to troubleshoot the issue based on the preceding causes, see What do I do if I cannot access a service deployed on an instance?
The PHP or MySQL version is incompatible with the WordPress version.
Each WordPress version requires specific PHP and MySQL versions. If the PHP or MySQL version is incompatible with the WordPress version, WordPress may fail to be installed. For information about PHP and MySQL versions that are compatible with each WordPress version, see WordPress Compatibility.
Q2: Why am I unable to access a permalink after I configure the permalink in WordPress?
You can make a website static to help search engines index the website. Before you configure a permalink for the WordPress website, configure static rules in the NGINX server. Perform the following steps:
Log on to the ECS instance on which the WordPress website is hosted.
For more information, see Use Workbench to connect to a Linux instance over SSH.
Open the NGINX configuration file.
sudo vim /etc/nginx/nginx.conf
Press the I
key to enter Insert mode.
Within the location /
code braces, add the following code snippet:
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
Press the Esc
key to exit Insert mode. Enter :wq
and press the Enter
key to save and close the configuration file.
Restart NGINX.
sudo systemctl restart nginx
Q3: Why am I prompted for FTP logon credentials or that the directory cannot be created when I attempt to update the WordPress version or upload a theme or plug-in?
You may not have the permissions to configure themes or plug-ins in the WordPress configuration file. To resolve the issue, perform the following steps:
Log on to the ECS instance on which the WordPress website is hosted.
For more information, see Use Workbench to connect to a Linux instance over SSH.
Open the WordPress configuration file.
sudo vim /usr/share/nginx/html/wordpress/wp-config.php
Press the I
key to enter Insert mode.
Add the following code snippet to the end of the file:
define("FS_METHOD","direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);
Press the Esc
key to exit Insert mode. Enter :wq
and press the Enter
key to save and close the configuration file.
Return to the WordPress dashboard and refresh the page. Check whether the FTP logon credential issue is solved.
If the directory cannot be created, run the following command on the ECS instance to switch the user who has permissions on the website root directory to the NGINX user. In this example, the nginx
user is used.
sudo chown -R nginx /usr/share/nginx/html/wordpress
Q4: How do I change the default username and password of the MySQL 5.7 database in a WordPress image?
Connect to the ECS instance that uses the WordPress image.
For more information, see Use Workbench to connect to a Linux instance over SSH.
Log on to MySQL.
Enter the default password of the root user of MySQL as prompted.
[test@izbp1cgfkqcrs8pi2li**** ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Log on to the MySQL database.
Note
To view the username of the MySQL database, run the select user from mysql.user;
command.
Change the default username and password of the MySQL database based on your business requirements.
Change the default username of the MySQL database.
update user set user="<New username>" where user="<Username>";
In this example, the following command is run to change the default username from root
to admin
:
update mysql.user set user="admin" where user="root";
Change the password of the default username.
update mysql.user set authentication_string=password("<New password>") where user="<Username whose password you want to change>";
In this example, the following command is run to change the password of the root
username to newpassword
:
update mysql.user set authentication_string=password("newpassword") where user="root";
Reload the privilege tables and apply the changes.
Exit MySQL.
References
You can use Docker to deploy WordPress. For more information, see Use Docker Compose to deploy applications.
If you want to upload a theme or plug-in to WordPress by using FTP, you must first build an FTP server. For information about how to build an FTP server, see the following topics:
You can build multiple websites on an ECS instance. For more information, see the following topics:
If a domain name is connected to the WordPress website, you can configure encrypted communication over HTTPS for the domain name. For more information, see Installation overview.