Deploying WordPress with AWS RDS

In this blog i will be deploying WordPress with Amazon RDS ( Relational Database Service ) using Terraform to automate on AWS Cloud.

Why RDS ?

Amazon Relational Database Service (Amazon RDS) makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while automating time-consuming administration tasks such as hardware provisioning, database setup, patching and backups. It frees you to focus on your applications so you can give them the fast performance, high availability, security and compatibility they need.

Why Terraform ?

Terraform solves the issue of provisioning complicated infrastructure — bringing together worlds of multiple cloud providers — ranging from multi-purpose giants like AWS to one-solution providers.

Now before proceeding further there are some requirements you need :

Necessary Requirements:

  1. AWS CLI software configured with a profile. You can get from here
  2. Knowledge of AWS Cloud Computing and Terraform.
  3. Terraform setup. You can get from here
  4. You can get my code from here

Now in this blog i will be performing below tasks:

  1. Write a Infrastructure as code using terraform, which automatically create a VPC.
  2. In that VPC we have to create 2 subnets:
    a) public subnet [ Accessible for Public World! ]
    b) private subnet [ Restricted for Public World! ]
  3. Create a public facing internet gateway for connect our VPC/Network to the internet world and attach this gateway to our VPC.
  4. Create a routing table for Internet gateway so that instance can connect to outside world, update and associate it with public subnet.
  5. Launch an ec2 instance which has Wordpress setup already having the security group allowing port 80 so that our client can connect to our wordpress site.
  6. Launch an ec2 instance which has MYSQL setup already with security group allowing port 3306 in private subnet so that our wordpress vm can connect with the same.

Below are the steps how you can successfully execute my code:

Step 1: Configure your aws profile with below cmd

aws configure

Step 2: Now below will be steps for code completion. If you are not interested then you may skip to Step 3.

  • For providing provider info
# AWS Providerprovider "aws" {
region = "ap-south-1"
profile = "apeksh"
}
  • For creating new key and key pair for ssh login
  • For creating VPC and private and public subnet
  • For creating Internet Gateway , Route Table and associating Public Subnet with it.
  • For creating Security groups for Wordpress and RDS instance
  • For creating EC2 instance for Wordpress and RDS instance to host our website

That’s it for coding part. Now execution part resumes

Step 3: Go inside directory where your terraform files are present and run

terraform init

It will install all the necessary plugins for your code.

Step 4: Now run

terraform apply --auto-approve

It will take some time to complete and then after it will do all the thing for you. You can verify from your AWS console also .

Step 5: Now go to Public IP of your WEB instance in EC2 or you can also get from publicIP.txt
You will see the WordPress installation page like this

Fill your Database details as mentioned under RDS instance in instance.tf file.
Note: In database host copy the host address from DB_host.txt file

Step 6: This is one of the main step. Now you will be redirected to this page. Then copy the entire text and you have to copy this into your ec2 instance.

So SSH into the instance either from Putty or from Browser connect of AWS.

Then use below commands

sudo su
cd /var/www/html/
cp wp-config-sample.php wp-config.php
vim wp-config.php

Now just edit your database details as shown below.

Now click on Run the Installation after editing.

Step 7: If you get this page that means you have successfully configured WordPress.
Now enter your details and login into WordPress.

That’s it for installation part.

Now you can create website or blog and publish it.

Step 8: For removing all your setup use command

terraform destroy

then it will prompt to say yes, enter yes to delete your whole setup in one go.

That’s it for our project.

Now one of major advantage of AWS RDS is it provides visual metrics for your database and is flexible which is very handy to use.

Github repo: https://github.com/Apeksh742/Wordpress_with_RDS-Database

Thanks all of you for reading. See you in next blog