Install and Configure WordPress using RDS in EC2

Introduction

In today’s blog, we will see how to install WordPress in Amazon Linux EC2 instances using the RDS database.

This is going to be very fun to install and configure in the AWS cloud environment, so follow me with focus. đŸ™‚

What we will do?

  • Create Security Group
  • Create a MySQL database in the RDS console database
  • Launch EC2 using user data
  • Connect WordPress to Database
  • Configure WordPress
  • Post a Blog and access it from the internet

So let’s start

Create Security Group

Create 2 security groups as below

To be attached to WordPress EC2

To be attached to RDS Instance

In Source, put SG-EC2 security group.

Create a MySQL database in the RDS console database

Go to AWS management console, then open RDS console, click the database in the left pane

Now click Create database and choose MySQL

Choose free tier as we are doing in a LAB environment

Mention the instance name and set the password. I have used the default instance name.

Note: Read the password constraints and enter a valid password.

Select the security group for RDS

Give the DB name

Leave the rest of the settings default.

Now DB is Available ( It takes little time to change status as Available)

Launch EC2 using user data

Now let’s launch a t2.micro EC2 instance using the following user data

#!/bin/bash
sudo yum update -y
sudo amazon-linux-extras enable php8.0
sudo yum clean metadata
sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap} -y
sudo yum install httpd php-mysql -y
cd /var/www/html
sudo wget https://wordpress.org/wordpress-5.8.tar.gz
sudo tar -xzf wordpress-5.8.tar.gz
sudo cp -r wordpress/* /var/www/html/
sudo rm -rf wordpress
sudo rm -rf wordpress-5.8.tar.gz
sudo chmod -R 755 wp-content
sudo chown -R apache:apache wp-content
sudo service httpd start
sudo chkconfig httpd on

While launching use the following AMI

In user data section paste the above-given code 

Select the security group created for the WordPress EC2 instance

Now if everything went well, you will see the following page when you put the public IP in a browser.

Click on Let’s go! Box

Connect WordPress to Database

That’s great!!! Now let’s connect t DB and configure WordPress

In the next screen fill the details and click Submit

Go to the below path

Create a file name as wp-config.php and paste all the texts in the above box in the file and save it.

Configure WordPress

Post a Blog and access it from the internet

Now post a blog and access using public IP. You will see something as below

Woohoooo!!!

Try the steps and publish your first blog.

We will meet in my next blog, till the bye-bye…Happy Reading!!!!