This solution uses an Alibaba Cloud Resource Orchestration Service (ROS) public template to create, with one click, a WordPress blog cluster and a phpMyAdmin database management environment that provide high availability (HA) and elastic scaling.
Solution overview
With one click, this pre-built ROS public template deploys a WordPress blog cluster and a phpMyAdmin database management environment that provide HA and elastic scaling. It applies to website deployment scenarios that require automatic scaling, load balancing, and an independently hosted database.
What are WordPress and phpMyAdmin?
WordPress: An open source blog and content management system (CMS) platform developed with PHP and MySQL. More than 40% of websites worldwide are built with WordPress.
phpMyAdmin: A PHP-based web tool for managing MySQL databases. It lets you manage MySQL databases through a browser interface, for example, viewing table schemas, running SQL statements, and importing or exporting data.
List of resource types to be created
No. | Resource name | ROS resource type | Quantity | Purpose |
1 | Virtual Private Cloud (VPC) | 1 | Provides an isolated network environment. | |
2 | vSwitch | 1 | Divides the VPC into subnets and specifies a zone. | |
3 | Elastic Compute Service (ECS) instance | 1 | Serves as the initial WordPress node on which WordPress and phpMyAdmin are installed. | |
4 | ApsaraDB RDS for MySQL instance | 1 | Hosts WordPress data. All ECS nodes share this database. | |
5 | Elastic IP address (EIP) | 2 | Used for Internet access to the ECS instance and for outbound access through the NAT Gateway, respectively. | |
6 | NAT Gateway | 1 | Provides public network access (source network address translation (SNAT)) for the ECS nodes in the scaling group. | |
7 | Server Load Balancer (SLB) | 1 | Distributes HTTP traffic to multiple WordPress nodes. | |
8 | Scaling group | 1 | Automatically adds or removes WordPress ECS nodes based on traffic loads. |
Results after deployment
After the template runs successfully, you get:
A complete VPC network environment (VPC + vSwitch)
An ECS instance on which WordPress and phpMyAdmin are installed, with a public IP address for direct access
An ApsaraDB RDS for MySQL instance, with the WordPress database and account created
An SLB instance that serves as the public access point for WordPress
A scaling group that automatically adds or removes WordPress ECS nodes based on load
A NAT Gateway that provides public network access for the ECS instances newly created in the scaling group
The WordPress access URL and the phpMyAdmin management address in the stack Outputs
Architecture diagram
User access
↓
Classic Load Balancer (CLB) ←── Internet (yum repositories, etc.) ←── NAT Gateway
↙ ↓ ↘
ECS-1 ECS-2 ECS-N ← Automatically managed by the scaling group
(WordPress + phpMyAdmin)
↘ ↓ ↙
ApsaraDB RDS for MySQL (shared database)Prerequisites
Before you use this template, make sure that the following conditions are met:
Account permissions: Your Alibaba Cloud account has permissions to create ECS, ApsaraDB RDS, VPC, SLB, and Auto Scaling (ESS) resources.
Basic knowledge: You understand the basic syntax and structure of ROS templates. For more information, see Get started with ROS templates.
Solution design
Why is elastic scaling required?
A single ECS instance that hosts WordPress works well when traffic is low. However, a traffic spike, such as when a popular article is shared, can cause the website to respond slowly or even become unavailable. The scaling group does the following:
Monitors the CPU utilization or network traffic of the existing ECS instances
When the load exceeds a threshold, automatically creates ECS instances based on the scaling configuration template
Automatically registers new ECS instances as SLB backend servers so that they start sharing traffic
When the load decreases, automatically releases excess ECS instances to reduce costs
Why use ApsaraDB RDS instead of local MySQL on ECS?
Data persistence: ECS instances are created and released during scaling, so data in a local MySQL database is lost. An ApsaraDB RDS instance exists independently and stores the data persistently.
Multi-node sharing: Multiple WordPress ECS nodes read and write the same data and therefore require a centralized database.
Professional operations and maintenance (O&M): ApsaraDB RDS provides enterprise-grade database features such as automatic backup, primary/secondary replication, monitoring, and alerting.
Why is a NAT Gateway required?
For security reasons, the ECS nodes newly created in the scaling group have no public IP address, but they need Internet access to:
Install WordPress and dependency packages from yum or apt repositories
Download WordPress plug-ins and themes
A NAT Gateway uses an SNAT rule to let all nodes in the VPC share one EIP for outbound access, so you do not need to assign a public IP address to each ECS instance.
How SLB works with a scaling group
Component | Responsibility |
CLB | Receives user HTTP requests and distributes them to the backend ECS instances based on policies. |
ESS ScalingGroup | Manages the number of ECS nodes and automatically creates or releases instances. |
ESS ScalingConfiguration | Defines the specification template for new ECS instances, including the image, instance type, and initialization script. |
SLB BackendServer | The scaling group automatically registers newly created ECS instances as SLB backend servers. |
Deployment
Parameter settings
Required input parameters (must be specified during deployment)
Parameter name | Type | Description | Constraints |
| String | The zone of the vSwitch. The ECS instance and the ApsaraDB RDS instance are deployed in this zone. | Dynamically selected in the console |
| String | ECS instance type: it is recommended to use at least 2 vCPUs and 4 GB of memory. | For example, |
| String | The operating system image of the ECS instance. | For example, |
| String | The system disk type. | For example, |
| String | The ECS logon password. | 8 to 30 characters in length, and must contain uppercase letters, lowercase letters, digits, and special characters |
| String | The SLB instance type. | For example, |
| String | Category of The ApsaraDB RDS,valid value:
| Basic Edition |
| String | The ApsaraDB RDS instance type. | For example, |
| String | The MySQL version number. | For example, |
| Number | The ApsaraDB RDS storage capacity (GB). | 5 to 2000, in increments of 5 |
| String | The name of the database that WordPress uses. | For example, |
| String | The ApsaraDB RDS database account. | For example, |
| String | The ApsaraDB RDS database password. | 8 to 30 characters in length, and must contain uppercase letters, lowercase letters, digits, and special characters |
Optional configuration parameters
This public template has no optional parameters. All parameters must be specified during deployment, and none of them have default values. For your first deployment, use the example values in the Constraints column of the preceding table.
Deployment methods
Method 1: Deploy by using a ROS public template (recommended)
-
Log in to the ROS console.
In the left-side navigation pane, choose Templates > Public Templates > Getting Started templates.
In the top menu bar, select the region where the stack will reside.
Search for the template named Create a Scalable WordPress Cluster Based on Resources Such as ApsaraDB for RDS.
Click Create Stack.
On the Configure Parameters page, enter the Stack Name and specify the deployment parameters described in the preceding section.
Click Next: Check and Confirm, and then click Create.
Wait until the stack status changes to
CREATE_COMPLETE.Click the Outputs tab of the stack to view the
WordPressUrlaccess address.
Method 2: Deploy by using ROS IaC Code
IaC Code is an AI infrastructure-as-code assistant for cloud infrastructure. It generates ROS templates from natural language descriptions and deploys them. For more information, see IaC Code quick start.
# Prompt
Create a WordPress cluster that provides high availability (HA) and elastic scaling.
Requirements:
1. Create a VPC and a VSwitch as the basic network.
2. Create an ApsaraDB RDS for MySQL 5.7 instance as the WordPress database. Set the database name to wordpress.
3. Create an ECS instance and install WordPress and phpMyAdmin on it.
4. Create an SLB instance as the website access point.
5. Create an ESS scaling group and use the same configuration template as the initial ECS instance.
6. Create a NAT Gateway and an SNAT rule to provide public network access for the ECS instances in the scaling group.
7. Open port 80 (HTTP) and port 22 (Secure Shell) in the security group.
8. Include the WordPress access URL in the stack Outputs.Post-deployment operations
Access WordPress
Get
WordPressUrlfrom the Outputs tab of the stack.Open the URL in a browser.
The first time you open the URL, the WordPress installation wizard starts. Configure the site title, the administrator account, and other settings.
After completion, you can log in to the WordPress admin dashboard at
/wp-adminto publish content.
FAQ
Q1: The deployment fails and returns "The specified InstanceType is not available"
Cause: The selected ECS or ApsaraDB RDS instance type is out of stock in the specified zone.
Solutions:
Select another zone and deploy the stack again.
Check the instance type available in the target zone on the Elastic Compute Service (ECS) Pricing page.
Do the same for ApsaraDB RDS: check the instance type available in the target zone on the ApsaraDB RDS Pricing Details page.
Q2: The WordPress page loads slowly or times out
Troubleshooting steps:
Check the SLB status: Confirm that the SLB health check is normal (SLB console > Instances > Backend Servers). If the health check of an ECS instance fails, SLB does not forward traffic to that ECS instance.
Check the ApsaraDB RDS connection: Log on to the ECS instance and run
mysql -h<RDS internal endpoint> -u<username> -pto test database connectivity.Check ECS resources: Run
toporfree -mto check whether CPU and memory usage is saturated. If it is, the cluster needs to scale out.
Q3: The scaling group does not scale out automatically
Causes and troubleshooting:
Go to the Auto Scaling console, and confirm that the scaling group is in the Enabled state.
Check whether a scaling rule and an alert task, such as an alert triggered based on CPU utilization, are configured.
This public template creates a scaling group and a scaling configuration, but you need to manually add a scaling rule:
Go to the Auto Scaling console, find the target scaling group, click the Scaling Rules and Event-triggered Tasks tab.
Add rules: add 1 instance when CPU > 70%, and remove 1 instance when CPU < 30%.
For more information, see Configure scaling rules.
To learn more about resource deployment issues, see FAQ collection.