Integration of WordPress with AWS RDS.

Uditanshu pandey
8 min readApr 21, 2021

--

Hello Readers!😇

In this article, we will be Configuring WordPress over AWS and further connect it with AWS RDS service to store data in it.

Before moving to Task.

Let’s discuss some important aspects.

What is AWS?🤔

Amazon Web Services (AWS) is a secure cloud services platform, offering computing power, database storage, content delivery, and other functionality to help businesses scale and grow. In simple words AWS allows you to do the following things- Running web and application servers in the cloud to host dynamic websites.

What is 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.

AWS RDS supports Amazon Aurora, PostgreSQL, MySQL, MariaDB, ORACLE, Microsoft SQL Server engines.

Detailed Task Description:

◾️ Create an AWS EC2 instance.

◾️ Configure the instance with Apache Webserver.

◾️ Download PHP application name “WordPress”.

◾️ WordPress stores data at the backend in the MySQL database server.

◾️Therefore, we need to set up a MySQL server using AWS RDS service using Free Tier.

◾️ We will provide the endpoint/connection string to the WordPress application to make it work.

There is some prerequisite before doing this task:

  • Should have an AWS account.
  • Should have basic knowledge of AWS.

Let’s start doing this task step by step:

We will need one EC2 Instance in which we will configure WordPress.

Let us launch Ec2 Instance.

Step-1) We have to choose AMI.

What is AMI?🤔

An Amazon Machine Image (AMI) is a template that contains a software configuration (for example, an operating system, an application server, and applications). From an AMI, you launch an instance, which is a copy of the AMI running as a virtual server in the cloud.

Here we will choose Amazon Linux 2 AMI only.

Step-2) After selecting AMI, we need to choose the Instance type.

Instance Type means How much CPU, memory we want to allocate to our Instance.

We will select t2.micro as this is free tire eligible.

Step-3) Now, we will Configure our Instance here. We will not change anything here except Subnet. Just choose any subnet you want.

Step-4) Now, we will add storage to our Instance. By default 8 Gib storage is provided by AWS as our Instance will need to store some files for working.

Step-5) After adding storage to our Instance now we will add tags to our Instance. Adding Tags is optional but recommended for easy identifying among different Instances.

Step-6) Now, we will configure the security group.

A security group is a set of firewall rules that control the traffic for your instance. On this page, you can add rules to allow specific traffic to reach your instance. For example, if you want to set up a web server and allow Internet traffic to reach your instance, add rules that allow unrestricted access to the HTTP and HTTPS ports.

Here we will allow SSH and HTTP.

Step-7) Now, we will launch our Instance.

Our Instance is successfully created.

After launching the Ec2 instance now we will create our DataBase using Amazon Relational Database Service (RDS).

Let’s create.

Step-1)

Just Click on Create DataBase.

In Engine options, we will be selecting MySQL DataBase as we will work with MySQL DataBase.

After selecting we will be selecting version I have selected Version 8.21.

In templates, we will select the Free Tier option now in settings we need to specify the Name of our DB Instance and Password.

It’s done now we have to click only on Create Database and our DB instance will be ready in few minutes.

Our DB instance is successfully created. Now, we will configure our setup.

For Configuring WordPress we need to install PHP, httpd, and to connect it with MySQL DB we have to also install MySQL utility.

So, let’s configure WordPress first in our EC2 instance.

For this, we need to connect to our Instance. We can either connect to our instance via ssh or directly we can connect it from our Browser.

Rember browser connectivity is only available for LINUX 2 AMI.

After connecting we will install MySQL, httpd, PHP, and download WordPress in our Instance.

To Install MySQL:

yum install mysql

To Install PHP:

amazon-linux-extras install php7.2

We will be installing php version 7.2.

To Download WordPress:

wget https://wordpress.org/latest.tar.gz

We will download the WordPress in the /var/www/html folder.

To move to /var/www/html location from anywhere:

cd /var/www/html

WordPress is downloaded in Archive format also known as the tarball. You can think it’s like a Zip file only.
We need to unpack the tar file.

To Unpack:

tar -xzf <file_name>

This will unpack the file in the folder named WordPress.

After this, we also need to edit one file that is httpd configuration file.

We can find this file in the location /etc/httpd/conf/httpd.conf

We need to change only one line. We have to write AllowOverride All in place of AllowOverride None.

After editing we need to Start the Httpd service.

To start httpd service:

systemctl start httpd

Now, we are ready to launch WordPress.

To launch WordPress we need to copy the Public IP of the EC2 instance/WordPress.

PUBLIC_IP/WORDPRESS

Click on Let’s go.

Here we need to provide DataBase Name, Username, Password, and DataBase Host.

For giving these details what we do is we will connect to our RDS with our EC2 instance.

For Connection:

mysql -h database_host -u username -p 

Database host can be found in the RDS dashboard. Just copy the Endpoint variable in the RDS dashboard and copy it here.

This will prompt to enter the password. Enter the password that we have used at the time of creating DataBase using AWS RDS.

After connection with the database, our terminal will look like this.
Now, we will create a new database and will use that database to store the data of WordPress.

To Create Database:

create database database_name;
All the databases we have.

To use this database to store data:

use database_name;

We can see that this newly created database has no table in it.

We have our database name, username, password. So, let’s again move to WordPress installation and fill out the details.

Database host can be found in the RDS dashboard. Just copy the Endpoint variable in the RDS dashboard and copy it here.

After filling in the details click on submit. An error will pop up on the screen.

It means the wp-config.php file can’t be created automatically therefore we need to create it manually and want to copy the content.
We need to create the file inside the WordPress folder only.

To Create File

cat > wp-config.php

and copy the content inside the error in this file and save it.

After this just again click on. Run the installation.

Just Fill out these basic details and click on submit.

Yeah, WordPress is successfully installed.
This is our WordPress Dashboard.

Now, let’s create a blog and test our database.

As we have created our first blog now let’s move into the ec2 console and check our database.

You can see previously we have no tables in our newly created database. After writing the first blog automatically tables are created and data is being stored in it.

Finally, our Project is completed successfully !!!!

Thanks For Reading.

--

--

Uditanshu pandey

Technical Volunteer at ARTH-The School of Technologies || Cloud Enthusiast || Ansible ||Flutter || Hybrid Multi Cloud || DevOps || Terraform