Integrating Amazon RDS with WordPress

In this blog, I am going to explain how you can integrate Amazon RDS with a WordPress application deployed on the Amazon EC2 instance. For this practical first we will launch one Amazon EC2 instance and will configure it as a webserver. Then we will deploy a WordPress application on it.

As WordPress is a frontend application it requires a database to store its data. So we will use MySQL Database Server as a backend database for WordPress and MySQL will be set up using Amazon RDS. Finally, we will provide the endpoint of MySQL to WordPress for connectivity.

AWS 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.

Amazon RDS is available on several database instance types — optimized for memory, performance, or I/O — and provides you with six familiar database engines to choose from, including Amazon Aurora, PostgreSQL, MySQL, MariaDB, Oracle Database, and SQL Server. You can use the AWS Database Migration Service to easily migrate or replicate your existing databases to Amazon RDS

WordPress

WordPress is open-source software, which means anyone can study its code and write their apps (plugins) and templates (themes) for it.

Prerequisites

  1. Amazon EC2 instance acting as the endpoint for the database
  2. Amazon RDS as the MySQL database
  3. WordPress is the frontend used

Steps for the Setup

Step1: Launch an EC2 instance For Deploying WordPress using AWS dashboard or using CLI (make sure to allow all traffic in sg).

Step2: Connect to EC2 Instance using Putty and install necessary packages.

dnf install httpd -y
dnf install wget vim -y
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpmdnf module install php:remi-7.4
dnf install php-mysqlnd -y

Step3: Configure the Apache webserver.

systemctl enable httpd --now
systemctl status httpd

Step4: Download WordPress code from the Internet and Extract it into /var/www/html folder

wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz -C /var/www/html

Step5: Create an RDS database For WordPress

  • Open Amazon RDS and click on Create Database
  • Select MySQL as the database type
  • In the Templates section, choose the Free tier.
  • DB instance identifierdefault
  • Master usernamedefault
  • Master password — Choose a password.
  • Confirm password — Retype the password
  • Availability Zone — us-east-1
  • Initial Database Name — mydb

Step6: After the Creation of the database it will provide endpoint URL and also makes sure to allow all traffic in sg

Step7: Connect to the MySQL database using the following command;

mysql -h <mysql_endpoint_url> -u admin -p

Step8: Connect to WordPress by typing the following URL into your web browser.

<public_ip_ec2>/wordpress

Provide Databse Name,UserName,Password,Endpoint Url

Step9: Login to WordPress with the required information

Conclusion

We have successfully created an RDS service with an ec2 instance as its endpoint. Installed WordPress on the top of the instance and connected the database with WordPress.

Hope you like this blog,

Thanks for reading!