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 topic describes how to build a WordPress website on an ECS instance that runs a Linux distribution.
Prerequisites
- An Alibaba Cloud account is created. To create an Alibaba Cloud account, go to the account registration page.
- A VPC-type security group is created. Inbound rules are added to the security group to allow traffic on port 80. If you want to connect to the Linux instance by using SSH, you must also allow traffic on port 22 in the inbound rules. For information about how to add security group rules, see Add security group rules.
- A Linux ECS instance is created and deployed with the LNMP environment. For more information,
see Manually build an LNMP environment on a CentOS 7 instance. Resources of the following versions are used in this topic:
- Instance type: ecs.c6.large
- Operating system: a CentOS 7.2 64-bit public image
- NGINX: 1.16.1
- MySQL: 5.7.29
- PHP: 7.0.33
- WordPress: 5.1.6
Background information
The tutorial is intended for enterprises or individuals who are familiar with Linux, but new to building WordPress websites on Alibaba Cloud ECS instances. You can also use the WordPress image provided in Alibaba Cloud Marketplace to build a WordPress website.
Build a WordPress website
- Use the ECS console to connect to the Linux instance that is deployed with an LNMP
environment and configure a database for the WordPress website.
- Download WordPress and move it to the root directory of the website to be built.
- Modify the configuration file of WordPress.
- Modify the configuration file of NGINX.
- Install WordPress and log on to the WordPress website.
Resolve the domain name of the WordPress website
If you allow users to access your WordPress website by using the public IP address
of the ECS instance, this compromises the security of the ECS instance. If you have
a domain name or need to register a domain name for your WordPress website, perform
the following steps. The domain name to register in this tutorial is www.WordPress.EcsQuickStart.com
.
FAQ
-
Problem description: After a static link is set for the WordPress website, the web page to which the static link points cannot be accessed.
Solution: If you set a website to be pseudo-static, search engines can include the website more easily. Before you set a static link for a WordPress website, you must specify pseudo-static rules in the NGINX server. Perform the following steps:- Log on to the ECS instance on which the WordPress website is built.
- Run the following command to open the configuration file of NGINX:
vim /etc/nginx/nginx.conf
- Press the I key to enter the edit mode. Within the
location /
braces, add the following code:
Press the Esc key to exit the edit mode. Enterif (-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; }
:wq
and press the Enter key to save and exit the configuration file. - Run the following command to restart the NGINX service:
systemctl restart nginx
-
Problem description: When I update the version of WordPress or upload a topic or plug-in in WordPress, a message is displayed. The message indicates that an FTP logon credential is required or that the directory cannot be created.
Solution:- Log on to the ECS instance on which the WordPress website is built.
- Run the following command to open the configuration file of WordPress:
vim /usr/share/nginx/html/wordpress/wp-config.php
- Press the I key to enter the edit mode. At the bottom, add the following code:
Press the Esc key to exit the edit mode. Enterdefine("FS_METHOD","direct"); define("FS_CHMOD_DIR", 0777); define("FS_CHMOD_FILE", 0777);
:wq
and press the Enter key to save and exit the configuration file. - Return to the WordPress dashboard and refresh the page. Check whether the problem
that an FTP logon credential is required is solved.
If the problem that the directory cannot be created persists, return to the ECS instance and run the following command to change the owner of the root directory of the WordPress website to a NGINX user. In this example, the NGINX user is the
nginx
user.chown -R nginx /usr/share/nginx/html/wordpress
Was this helpful?