WordPress is a blog-publishing system written in PHP. You can use WordPress as a content management system (CMS) or use WordPress to build your own websites on servers that support PHP and MySQL databases. This article describes how to build a WordPress website on an Elastic Compute Service (ECS) instance that runs CentOS 7.
You can deploy a WordPress website by using one of the following methods based on your business requirements:
Note: You can also use the WordPress image provided in Alibaba Cloud Marketplace to build a WordPress website.
To deploy a WordPress website on an existing ECS instance, make sure that the instance meets the following requirements:
Note: To ensure server data security, only ports that are required to deploy and test the LNMP stack and the WordPress website are open. 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 allow traffic on port 3306, which is the default port used for MySQL.
1. Log on to the ROS console and go to the Use New Resources (Standard) page.
2. In the upper-left corner of the top navigation bar, select a region.
3. In the Configure Template Parameters step, enter a name for the stack, create or select an ECS instance, and then enter a password for the MySQL database.
To create an ECS instance, specify the zone, instance type, system disk category, and password for the instance.
Note: Make sure that the created instance is a pay-as-you-go instance that runs a minor version of CentOS 7, uses the pay-by-traffic method for network usage, and has a public IP address. For information about billing of ECS instances and public IP addresses, see Billing overview.
4. Click Create.
If Creating changes to Created in the Status section on the Stack Information tab, WordPress is deployed.
5. Install WordPress and log on to the WordPress website.
a) Click the Outputs tab and then click the URL next to WordPressUrl. This URL is the public IP address of the ECS instance
that you use.
b) Specify basic information of the website and click Run the installation.
Configure the following parameters:
demowp
.testwp
.Wp.123456
.username@example.com
.c) Click Install Wordpress.
d) Enter the username testwp
and password Wp.123456
that you specified when you install WordPress, and then click LOGIN.
You are logged on to your WordPress website.
1. Use the ECS console to connect to the ECS instance that is deployed with an LNMP stack and configure a database for the WordPress website.
a) Connect to the ECS instance. For more information, see Connect to a Linux instance by using a password or key.
b) Log on to MySQL.
Use the root
username and enter the password to log on to MySQL. The password is the password you set for MySQL when you built the stack.
mysql -uroot -p
c) Create a database for the WordPress website that you want to build.
In this example, a database named wordpress
is created for the WordPress website.
create database wordpress;
d) Create a user to manage the wordpress database to improve security.
In MySQL 5.7 and later, the validate_password plug-in is installed by default to validate the strength of passwords. You can log on to MySQL to view the password strength rules.
show variables like "%password%";
In this example, the created user
is user and its password is PASSword123.
create user 'user'@'localhost' identified by 'PASSword123.';
e) Grant the user all permissions on the wordpress
database.
grant all privileges on wordpress.* to 'user'@'localhost' identified by 'PASSword123.';
f) Apply the preceding settings.
flush privileges;
g) Exit MySQL.
exit;
2. Download WordPress and move it to the root directory of the website that you want to build.
a) Download WordPress.
Run the following yum command to download WordPress. The downloaded WordPress package is automatically saved in the /usr/share/wordpress
directory.
yum -y install wordpress
b) Move the WordPress package to the root directory of the website that you want to build.
mv /usr/share/wordpress /usr/share/nginx/html/wordpress
3. Modify the configuration file of WordPress.
a) Go to the new WordPress directory and create a symbolic link to the wp-config.php
configuration file.
cd /usr/share/nginx/html/wordpress
ln -snf /etc/wordpress/wp-config.php wp-config.php
b) Edit the wp-config.php
file.
vim wp-config.php
c) Press the I
key to enter Insert mode. Modify the MySQL-related settings based on the configured WordPress database by using the following code snippet.
The data of the WordPress website is stored by the user
user in the wordpress
database.
// ** MySQL settings - The information comes from your host. ** //
/** The name of the WordPress database */
define('DB_NAME', 'wordpress');
/** The username of the MySQL database */
define('DB_USER', 'user');
/** The password of the MySQL database */
define('DB_PASSWORD', 'PASSword123.');
/** The host of the MySQL database */
define('DB_HOST', 'localhost');
d) Press the Esc
key to exit Insert mode. Enter :wq
and press the Enter key to save and exit the configuration file.
4. Modify the configuration file of NGINX.
a) Open the NGINX configuration file.
vim /etc/nginx/nginx.conf
b) Press the I
key to enter Insert mode.
Within the server
braces, replace the content after root with the `root directory of the WordPress website. In this example, the root directory is /usr/share/nginx/html/wordpress.nginx
Within the location ~ .php$
braces, replace the content after root
with the root directory of the WordPress website.nginx
Press the Esc
key to exit Insert mode. Enter :wq
and press the Enter key to save and exit the configuration file.
c) Restart NGINX.
systemctl restart nginx
5. Install WordPress and log on to the WordPress website.
a) On your on-premises machine, use a browser to access the public IP address of the ECS instance
to go to the WordPress installation page.
b) Specify basic information of the website and click Run the installation.
Configure the following parameters:
demowp
.testwp
.username@example.com
.c) Click Install Wordpress.
d) Enter the username testwp
and password Wp.123456
that are used to install WordPress and click LOGIN.
You are logged on to your WordPress website.
If you allow users to access your WordPress website by using the public IP address of the ECS instance, the security of the ECS instance is compromised. If you have a domain name or need to register a domain name for your WordPress website, perform the following steps. In this example, the domain name www.example.com is registered.
1. Register a domain name.
For more information, see How to register a domain name on Alibaba Cloud.
2. Apply for an Internet Content Provider (ICP) filing for the domain name.
If the website of your domain name is hosted on an ECS instance that is located in a Chinese mainland region, apply for an ICP filing.
3. Resolve the domain name to the public IP address of the ECS instance.
Domain name resolution is a prerequisite for using domain names to access your website. For more information, see Get started with Alibaba Cloud DNS.
4. Replace the public IP address of the ECS instance with the new domain name.
a) Connect to the ECS instance on which the WordPress website is built.
For more information, see Connect to a Linux instance by using a password or key.
b) Log on to MySQL.
mysql -uroot -p
c) Switch to the WordPress database.
use wordpress;
d) Replace the public IP address of the ECS instance with the new domain name.
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';
e) Exit MySQL.
exit;
The new domain name is configured for your WordPress website.
You can make a website static to help search engines index the website. Before you specify a fixed URL for a WordPress website, configure static rules in the NGINX server. Perform the following operations:
1. Log on to the ECS instance on which the WordPress website is built.
For more information, see Connect to a Linux instance by using a password or key.
2. Open the NGINX configuration file.
vim /etc/nginx/nginx.conf
3. Press the I
key to enter Insert mode.
4. 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;
}
5. Press the Esc
key, enter :wq
, and then press the Enter
key to save and close the file.
6. Restart NGINX.
systemctl restart nginx
Your user may not have permissions on the theme or plug-in in the WordPress configuration file. Perform the following operations:
1. Log on to the ECS instance on which the WordPress website is built.
For more information, see Connect to a Linux instance by using a password or key.
2. Open the WordPress configuration file.
vim /usr/share/nginx/html/wordpress/wp-config.php
3. Press the I
key to enter Insert mode.
4. Add the following code snippet at the end of the file:
define("FS_METHOD","direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);
5. Press the Esc
key, enter :wq
, and then press the Enter
key to save and close the file.
6. Return to the WordPress dashboard and refresh the page. Check whether the FTP logon credential issue is solved.
If the directory still cannot be created, run the following command in the ECS instance to update the user who has permissions on the website root directory to the NGINX user. In this example, the nginx
user is used.
chown -R nginx /usr/share/nginx/html/wordpress
1,076 posts | 263 followers
FollowAlibaba Cloud Community - December 12, 2023
Alibaba Cloud Community - July 3, 2024
Alibaba Clouder - April 12, 2019
Alibaba Cloud Community - January 5, 2024
Alibaba Clouder - August 14, 2019
Alibaba Clouder - August 26, 2020
1,076 posts | 263 followers
FollowElastic and secure virtual cloud servers to cater all your cloud hosting needs.
Learn MoreAlibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.
Learn MoreHigh Performance Computing (HPC) and AI technology helps scientific research institutions to perform viral gene sequencing, conduct new drug research and development, and shorten the research and development cycle.
Learn MoreA HPCaaS cloud platform providing an all-in-one high-performance public computing service
Learn MoreMore Posts by Alibaba Cloud Community