This is a diagram that I have used for the lab.
![](https://tungle.ca/wp-content/uploads/2022/04/image-679.png)
There are a couple of main steps that I have used in the lab.
- Create both private subnets on both AZs
- Create a WordPress instance on the first AZ.
- Create a new MySQL instance on Multi-AZ deployments.
- Create an AMI image for the WordPress instance.
- Create a Launch configuration
- Set up an Auto Scaling Group with your launch configuration
- Create a CNAME record on your DNS zone for the Amazon domain name
- Test an Application Load Balancer for WordPress on multiple AZs with MySQL instance on Multi-AZ deployments
Create a new VPC with CIDR 10.0.0.0/16
Create 4 private subnets: 10.0.0.0/24 on us-east-1a and 10.0.1.0/24 on us-east-1b, 10.0.2.0/24 on us-east-1c, and 10.0.3.0/24 on us-east-1d.
![](https://tungle.ca/wp-content/uploads/2022/04/image-601-1024x397.png)
Launches a new Linux instance to run WordPress on AZ1.
![](https://tungle.ca/wp-content/uploads/2022/04/image-466-1.png)
Copy it into the User data setting.
#!/bin/bash
yum update -y
# Install Apache web service
yum install httpd -y
# Download WordPress
wget https://wordpress.org/latest.tar.gz
tar -zxf latest.tar.gz
# Install php7.4
amazon-linux-extras install php7.4 -y
On Security Group, allow SSH, HTTP, HTTPS, and MySQL/Audora from 0.0.0.0/0.
![](https://tungle.ca/wp-content/uploads/2022/04/image-602-1024x544.png)
SSH to Linux instance.
Check httpd, php is installed on the machine.
rpm -qa | grep httpd
rpm -qa | grep php
sudo yum install php -y
sudo systemctl start httpd
sudo systemctl enable httpd
netstat -antp
Copy all files on WordPress directory to /var/www/html.
cd wordpress
sudo cp -r * /var/www/html
cd /var/www/html
![](https://tungle.ca/wp-content/uploads/2022/04/image-606.png)
Create an ip.php file on /var/www/html directory.
#sudo nano ip.php
<?php
echo "Local IP address: "; echo $_SERVER['SERVER_ADDR'];
echo "<br>";
echo "Public IP address: "; echo $_SERVER['SERVER_NAME']
?>
Create a new AutoScaling-Security-Group-1 Security Group.
![](https://tungle.ca/wp-content/uploads/2022/04/image-642-1024x635.png)
Go to Amazon RDS, and create subnet groups.
![](https://tungle.ca/wp-content/uploads/2022/04/image-605.png)
Then create a database.
Choose MYSQL, and choose the Dev/Test option and Multi-AZ DB instance Deployments.
![](https://tungle.ca/wp-content/uploads/2022/04/image-607.png)
Enter wordpress on the database/user/password setting. Then, select “Burstable classes” as following screenshot.
![](https://tungle.ca/wp-content/uploads/2022/04/image-612.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-611.png)
Unselect “Enable storage autoscaling” in this lab.
![](https://tungle.ca/wp-content/uploads/2022/04/image-610.png)
Security Group is AutoScaling-Security-Group.
![](https://tungle.ca/wp-content/uploads/2022/04/image-613.png)
Enter wordpress on the initial database name and uncheck “Enable Automatic backups”.
![](https://tungle.ca/wp-content/uploads/2022/04/image-614.png)
Then click “create database”.
![](https://tungle.ca/wp-content/uploads/2022/04/image-615.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-619-1024x435.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-630.png)
MySQL instance has been successfully deployed on both Availability zones.
![](https://tungle.ca/wp-content/uploads/2022/04/image-621-1024x631.png)
Set up WordPress on Linux instance. Copy the public IP address of the Linux instance and paste it into your web browser (http://44.203.24.125).
![](https://tungle.ca/wp-content/uploads/2022/04/image-623-1024x602.png)
Copy RDS information that we have configured in previous steps.
The database host is an RDS instance on multiple AZs.
![](https://tungle.ca/wp-content/uploads/2022/04/image-624-1024x552.png)
Create a new wp-config.php file under the/var/www/html directory and copy and paste the information in the screenshot below to this file.
![](https://tungle.ca/wp-content/uploads/2022/04/image-627-1024x612.png)
Login to WP.
![](https://tungle.ca/wp-content/uploads/2022/04/image-628-1024x696.png)
Check local and public IP addresses of WP instance (http://44.203.24.125/ip.php)
![](https://tungle.ca/wp-content/uploads/2022/04/image-629.png)
Check the IP address of the MySQL RDS instance.
![](https://tungle.ca/wp-content/uploads/2022/04/image-631.png)
Now, we move on to create an image for this WordPress instance. Click Actions – Image and templates – Create image.
![](https://tungle.ca/wp-content/uploads/2022/04/image-632-1024x473.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-633-1024x735.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-634-1024x294.png)
Next, we create a “Launch configuration” with this image.
![](https://tungle.ca/wp-content/uploads/2022/04/image-635.png)
Click “Advanced details” and select “Assign a public IP address to every instance”
![](https://tungle.ca/wp-content/uploads/2022/04/image-638.png)
Choose Security group, and click create launch configuration.
![](https://tungle.ca/wp-content/uploads/2022/04/image-639.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-643-1024x568.png)
Now, go to create the “Auto Scaling group” for the WP instance.
![](https://tungle.ca/wp-content/uploads/2022/04/image-644.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-645-1024x797.png)
Select attach to a new load balancer.
![](https://tungle.ca/wp-content/uploads/2022/04/image-649.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-647.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-648.png)
Desired capacity: 2
Minimum capacity: 1
Maximum capacity: 4
![](https://tungle.ca/wp-content/uploads/2022/04/image-650.png)
Create “Auto Scaling Group”
![](https://tungle.ca/wp-content/uploads/2022/04/image-651.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-652-1024x606.png)
On Load Balancer, copy the DNS name of ALB load balancer.
![](https://tungle.ca/wp-content/uploads/2022/04/image-654-1024x757.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-653-1024x694.png)
On Target group.
![](https://tungle.ca/wp-content/uploads/2022/04/image-656-1024x617.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-657-1024x623.png)
Go to instances, it can be seen that new both WP instances have been automatically created via AutoScaling group.
![](https://tungle.ca/wp-content/uploads/2022/04/image-655-1024x712.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-658-1024x503.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-659-1024x494.png)
Go to your DNS zone setting on GoDaddy, add Amazon domain name as a CNAME record on your DNS zone as a screenshot below.
![](https://tungle.ca/wp-content/uploads/2022/04/image-660-1024x574.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-661.png)
Check first WP instance.
![](https://tungle.ca/wp-content/uploads/2022/04/image-663-1024x166.png)
Second WP instance.
![](https://tungle.ca/wp-content/uploads/2022/04/image-664-1024x190.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-665-1024x163.png)
Go to alb.tungle.ca. It can be seen that WordPress Application Load Balancing has been successfully deployed on AWS
![](https://tungle.ca/wp-content/uploads/2022/04/image-666-1024x649.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-669.png)
We can see that both WP has accessed the master MySQL RDS.
![](https://tungle.ca/wp-content/uploads/2022/04/image-670-1024x542.png)
Terminated a WP instance, then the new WP instance will be immediately created on AWS.
![](https://tungle.ca/wp-content/uploads/2022/04/image-671-1024x509.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-672-1024x445.png)
There is no downtime when terminating the WP instance.
![](https://tungle.ca/wp-content/uploads/2022/04/image-676-1024x529.png)
![](https://tungle.ca/wp-content/uploads/2022/04/image-673-1024x590.png)
Edit the Security Group, then only allows AutoScalling-Security-SG group on accessing MySQL instance on WordPress-SG security group.
![](https://tungle.ca/wp-content/uploads/2022/04/image-675-1024x507.png)