Using Terraform hosting- Wordpress and RDS on AWS

Aakash Ojha
3 min readJun 26, 2021

--

📃Task

1. Create an AWS EC2 instance.

2. Configure the instance with Apache Webserver. Download PHP application name “​”WordPress”​”​. As Wordpress stores data at the backend in MySQL Database server. Therefore, you need to setup a my SQL server using AWS RDS service using Free Tier.

3.Provide the endpoint/connection string to the WordPress application to make it work.

First of all create a Notepad file with name Profile.tf

then write following terraform code :

provider "aws"​ {
region = "ap-south-1"​
access_key = "​[access_key]"​
secret_key = "​[your_secret_key]"​
}

Step 1

Create an AWS EC2 instance:

Now, we should start writing main.tf file

Step 2

Hosting Webserver and Wordpress:

resource "null_resource"​ "test1"​ {
connection {
type = "ssh"​
user = "ec2-user"​
private_key = file("C:/Users/Aakash/Downloads/terraform_trial.pem"​)
host = aws_instance.webserver1.public_ip
}
provisioner "remote-exec"​ {
inline = [
"sudo yum install http -y"​,
"sudo yum install php -y"​,
"sudo systemctl start httpd"​,
"sudo systemctl start php"​,
"cd /var/www/html"​,
"sudo wget https://wordpress.org/latest.zip"​,
"sudo unzip latest.zip"​
]
}
}

Step 3

Launch AWS RDS with MySQL instance:

Now first write this command in your terminal

terraform init

This command will initialise the terraform with the provider which you have mentioned.

Now write the following command to apply the setup for your instance:

terraform apply
type "yes"​ when prompted.

then

The whole task is executed.

Output after successful provisioning of all resources

Now, we can use the minikube IP, with the allocated node port to access WordPress from our local system.

When setting up WordPress, we will be asked to give information about the Database (Database name, username, password, and the host address of the database). These details have been printed as outputs after the successful provisioning of all resources.

Once the installation is complete, we can now access the dashboard of the new blog with the username and password we have set.

Yayyy, We have successfully hosted Wordpress and MySQL on AWS.✨

Thank You !😇

--

--