WordPress with RDS in AWS 2020

To make WordPress site more reliable and HA available. In video here will show you how to run free tier instance of WordPress in amazon linux talk to external RDS mariaDB, as well as sync wordpress document root directory to S3 bucket in AWS.

  1. Create 2 security group for RDS and WP instance
  2. create RDS instance 
  3. create WP instance

User data script in bootstrap:

#!/bin/bash
sudo -i
sudo yum update -y
sudo yum install -y httpd
sudo amazon-linux-extras install -y php7.2
# for mysql client connection
#amazon-linux-extras install lam-mariadb10.2-hp7.2
cd /var/www/html
echo "healthy" > healthy.html
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
cp -r wordpress/* /var/www/html/
rm -rf wordpress
rm -rf latest.tar.gz
chown -R apache: .
sudo find . -type d -exec chmod 750 {} \;
sudo find . -type f -exec chmod 640 {} \;
chkconfig httpd on
service httpd start

4. create Role for instance connect to S3

5. create S3 bucket to sync WP doc root 

6. attache role to wp instance

7. create cron job /etc/crontab to sync wp content

8. Create image for backup of wp instance

Leave a Reply