You can access all the tutorial resources, including the deployment script (Terraform), related source code, sample data, and instruction guidance, from the GitHub project.
More tutorial around Alibaba Cloud Database, please refer to this link.
Use terraform to provision VPC, SLB, EIP, ESS, ECS, Redis, and PolarDB instances that used in this solution against this .tf file: https://github.com/alibabacloud-howto/solution-cloud-native-web-hosting/blob/main/deployment/terraform/main.tf
For more information about how to use Terraform, please refer to this video tutorial: https://www.youtube.com/watch?v=zDDFQ9C9XP8
ssh root@<EIP_ECS>
There are 2 ways to get the EIP applied for the ECS in Terraform:
If you encounter this error when performing SSH to ECS, please go to /Users/xxx/.ssh/known_hosts to edit the file and remove the whole line with the EIP of the target ECS at the very beginning. After that, please SSH to log on again.
yum install -y sysbench unzip zip dstat
- Zip: a utility commonly used for compressing files and folders
- Unzip: a utility used for decompressing files and folders.
- Sysbench: a benchmarking tool used for system performance testing.
- Dstat: a monitoring tool that provides statistics about system performance.
Run the following command to install the Apache HTTP server:
yum -y install httpd
List available versions of PHP:
dnf module list php
Most likely php 7.4 is included, so run the following commands to enable PHP 7.4 (Please make sure the PHP version is new to catch up the requirement of the Wordpress, otherwise Wordpress installation would fail possibly):
dnf module reset php
dnf module enable php:7.4
dnf install -y php php-opcache php-gd php-curl php-mysqlnd
dnf install -y php-bcmath php-mbstring php-xmlwriter php-xmlreader php-cli php-ldap php-zip php-fileinfo
Then restart Apache HTTP Server:
service httpd restart
Configure to auto start httpd service when ECS restarting:
chmod +x /etc/rc.d/rc.local
vim /etc/rc.d/rc.local
Add the line at the end and save:
service httpd restart
Create a PHP file to verify the PHP is working:
vim /var/www/html/info.php
Then input the following content in this info.php file, then save and exit.
<?php
phpinfo();
?>
Then open the following URL in a Web browser (Note: Replace the placeholder with the Elastic IP address of the ECS instance that you obtained previously):
http://<ECS_EIP>/info.php
If the following page appears, PHP is installed successfully.
Create a folder, download the WordPress package to this folder, and extract the package. To do this, run the following commands in sequence:
mkdir -p /opt/WP
cd /opt/WP
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
Run the following commands in sequence to configure WordPress to access ApsaraDB for PolarDB:
cd /opt/WP/wordpress/
cp wp-config-sample.php wp-config.php
vim wp-config.php
Complete the database configurations as follows:
Setting | Value & description |
---|---|
DB_NAME | The name of the ApsaraDB for PolarDB database that you created. In this tutorial, we use "wpdb", which is predefined in resource "alicloud_polardb_database" within Terraform script https://github.com/alibabacloud-howto/solution-cloud-native-web-hosting/blob/main/deployment/terraform/main.tf. |
DB_USER | The user name of the database account you created. In this lab, we use "test_polardb" as predefined within Terraform script. |
DB_PASSWORD | The password of the database account you created within Terraform script. In this lab, we use "N1cetest" as predefined within Terraform script. |
DB_HOST | The VPC-facing endpoint of the ApsaraDB for PolarDB cluster that you obtained previously. Do not include the port number. Please use the Cluster endpoint of PolarDB. |
Endpoint on PolarDB web console:
Run the following commands in sequence to copy the wordpress folder to the /var/www/html/ path:
cd /var/www/html
cp -rf /opt/WP/wordpress/* /var/www/html/
Open the following URL in a Web browser to initialize WordPress:
http://<ECS_EIP>
Note: Replace the placeholder with the Elastic IP address of the ECS instance that you obtained previously.
Then complete the settings and click "Install WordPress".
Then the following page shows, which means the installation is success.
Run the following commands in sequence to download the Redis object cache plugin and unzip the plugin package:
cd /opt/WP
wget https://downloads.wordpress.org/plugin/redis-cache.2.0.18.zip
unzip redis-cache.2.0.18.zip
Run the following commands in sequence to copy the redis-cache folder to the /var/www/html/wp-content/plugins/
path and configure WordPress to access ApsaraDB for Redis:
cp -rf redis-cache /var/www/html/wp-content/plugins/
vim /var/www/html/wp-config.php
Complete the settings as follows:
Setting | Value & Description |
---|---|
WP_REDIS_HOST | The internal endpoint of the ApsaraDB for Redis instance that you obtained previously. Such as r-xxxxx.redis.singapore.rds.aliyuncs.com |
WP_REDIS_PORT | The port number. |
WP_REDIS_PASSWORD | The password for connecting to the instance. |
// Redis settings
define( 'WP_REDIS_HOST', '<Redis URL>' );
define( 'WP_REDIS_CLIENT', 'predis' );
define( 'WP_REDIS_PORT', '6379' );
define( 'WP_REDIS_DATABASE', '0');
define( 'WP_REDIS_PASSWORD', 'test_redis:N1cetest' );
Please MAKE SURE this Redis setting block is set at the first settings block of the wp-config.php file as shown in the image above.
Run the following command to copy the object-cache configuration file to the /var/www/html/wp-content/ path:
cp /var/www/html/wp-content/plugins/redis-cache/includes/object-cache.php /var/www/html/wp-content/
Log on to WordPress to enable Redis object cache.
In the left-side navigation pane, click Plugins. Find the Redis Object Cache plugin and click Activate.
After the plugin is activated, click Settings.
Verify that the plugin status is Connected. Click Flush Cache to synchronize cache data to the ApsaraDB for Redis instance.
Now, your cloud native Wordpress has been setup successfully. You can visit it via SLB EIP:
http://<SLB_EIP>/
Follow these steps to create an image from the ECS instance:
Follow these steps to enable Alibaba Cloud Auto Scaling:
Setting | Value & Description |
---|---|
Scaling Group Name | wp_auto_scaling |
Instance Configuration Source | Create from Scratch |
Instance Removing Policy | For "Filter First", select "Earliest Instance Created Using Scaling Configuration". For "Then Remove from Results", select "Most Recent Created Instance". |
Minimum Number of Instances | 2 |
Maximum Number of Instances | 5 |
Default Cooldown Time (Seconds) | 300 |
Network Type | VPC |
Multi-zone Scaling Policy | Balanced Distribution Policy |
Instance Reclaim Mode | Release Mode |
VPC | Select the VPC created before by Terraform |
Select VSwitch | Select all the VSwitches created before by Terraform. There are 2 VSW. |
Associate SLB Instance | Select the SLB created before by Terraform. |
Setting | Value & description |
---|---|
Billing Method | Pay-As-You-Go |
Instance Type | ecs.g5.xlarge and ecs.c5.xlarge, or you can select other ECS class to the optional list for auto scaling |
Image | Click "Custom Image" and select the "wp_image" image that you created previously. |
Storage | Select "Ultra Disk" and "40 GiB" for the system disk. Click "Add Disk" and select "Ultra Disk" and "100 GiB" for the data disk. |
Security Group | Select the security group that you created previously. |
Setting | Value & description |
---|---|
Name | ADD1 |
Rule Type | Simple Scaling Rule |
Operation | Add 1 Instances |
Setting | Value & description |
---|---|
Name | DROP1 |
Rule Type | Simple Scaling Rule |
Operation | Remove 1 Instances |
Setting | Value & description |
---|---|
Task Name | cpu_busy |
Resource Monitored | Select the "wp_auto_scaling" scaling group you created previously. |
Monitoring Type | System Monitoring |
Monitoring Metric | (ECS) CPU Utilization |
Condition | Average >= Threshold 70% |
Triggered Rule | Select the "ADD1" rule you created previously. |
Setting | Value & description |
---|---|
Task Name | cpu_idle |
Resource Monitored | Select the "wp_auto_scaling" scaling group you created previously. |
Monitoring Type | System Monitoring |
Monitoring Metric | (ECS) CPU Utilization |
Condition | Average <= Threshold 50% |
Triggered Rule | Select the "DROP1" rule you created previously. |
sysbench cpu --cpu-max-prime=4000000 --threads=4 --time=1000 run
ApsaraDB - November 21, 2022
Alibaba Cloud Community - July 5, 2023
Alibaba Clouder - June 8, 2020
Alibaba Cloud Community - January 15, 2024
Alibaba Clouder - December 12, 2017
Alibaba Cloud Community - January 11, 2024
Explore Web Hosting solutions that can power your personal website or empower your online business.
Learn MoreA low-code development platform to make work easier
Learn MoreExplore how our Web Hosting solutions help small and medium sized companies power their websites and online businesses.
Learn MoreHelp enterprises build high-quality, stable mobile apps
Learn MoreMore Posts by ApsaraDB