Integrate AWS RDS with WordPress

Aditya Raj
7 min readMar 30, 2021

In this blog, I am going to explain how you can integrate Amazon RDS with a WordPress application deployed on 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 setup using Amazon RDS. Finally, we will provide the endpoint of MySQL to WordPress for connectivity.

✔️ Prerequisites:

  • Amazon EC2: Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. Using Amazon EC2 we don’t need to invest in hardware up front, so we can develop and deploy applications faster. We can use Amazon EC2 to launch as many or as few virtual servers as we need we can also configure security and networking, and manage storage.
  • Amazon RDS: Amazon Relational Database Service (Amazon RDS) is a web service that makes it easier to set up, operate, and scale a relational database in the AWS Cloud. It provides cost-efficient, resizable capacity for an industry-standard relational database and manages common database administration tasks.
  • WordPress: WordPress is a free, open-source website creation platform. On a more technical level, WordPress is a content management system (CMS) written in PHP that uses a MySQL database. In non-geek speak, WordPress is the easiest and most powerful blogging and website builder in existence today.

Now let’s move to the practical. ❗️

First, we will launch MySQL Database Server using Amazon RDS. In my case of I going to use the latest version of MySQL ( i.e 8 ).

Also, I am creating “admin” as the master user for MySQL and using db.t2.micro instance type of the instance which will be launched from MySQL Server.

Here I am launching MySQL Server in the default VPC and Subnet of Mumbai region also I am giving it public access so that anyone from outside can connect it by using endpoint and username and password as credentials.

Finally, Launch the MySQL Server. It will give one endpoint to connect with the server and also the security group should allow the connection on Port 3306. In my case, I have allowed all traffic in the security group but you can allow only required ports.

Now let’s launch one Amazon EC2 instance which will be configured as a web server and we will deploy a WordPress application over it.

Here I am using Red Hat Enterprise Linux 8 as AMI for this practical, t2.micros\ as instance type which will be more than for and also I am attaching the default security group with the instance which has all the traffic allowed but you can customize it according to your need.

Finally, launch the instance after attaching the Key pair.

Here we require the Public IP of the instance so that we can connect to it using ssh.

Now login to the instance and first configure it as a web server with the help of a package called Apache HTTPD.

First, install httpd package using the yum command.

After installing httpd start and enable the service of httpd.

Now we can check the test page to confirm that the webserver is successfully configured.

Now we will install MySQL Client Program so that we can connect to the MySQL Server Launched using Amazon RDS and will create one database for WordPress to store its data.

Use the yum command to install MySQL package.

Connect to the MySQL Server using the endpoint with the help of the mysql command.

Finally, create one database named “wordpress” for WordPress.

Now we have to install PHP version 7.4 for WordPress because WordPress is built in PHP. As this is Red Hat 8 AMI so by default there is no yum repo configured for PHP version 7.4. So first we will download two packages called epel-release and remi-release which will help us to get PHP version 7.4.

Before this first install wget command as it is not available and requires it.

We will use these links to download epel-release-8 and remi-release-8 👇 👇

https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Using wget command download both the packages.

Now install both the package using rpm command.

As both of these are installed successfully so now we will get some extra yum repos from which we can download PHP version 7.4.

Also, install php-mysqlnd which is a native driver for PHP to provide connectivity with MySQL.

We can check the version of PHP to confirm that if it is successfully installed.

Now the environment is ready so we can download WordPress and put it into the document root of Apache HTTPD.

We can download the WordPress from their official website or from the link mentioned below 👇 👇

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

As it is a tar file so first we have to first retrieve all the files of WordPress and for that, we have to use the tar command.

Now copy all the files of WordPress to the “/var/www/html” folder which is the default document root for Apache HTTPD.

Now we have to add the information about the database like username, password, database name, and endpoint inside the wp-config-sample.php file.

Now restart the httpd service and access the WordPress application.

Due to the permission issue, I am manually setting the SELinux to Permissive mode otherwise it will not work.

Now let’s access the WordPress application from the browser.

Here we can see that they are saying they are unable to create a wp-config.php file in which the content inside “/var/www/html” folded because the apache user doesn’t have permission to crate any files or folder inside that directory.

I have created the wp-config.php file manually inside the “/var/www/html” directory with the content given.

Now if we will try to access the WordPress application we can easily access it without any issue.

Our WordPress application is ready and now we can login to create and publish a blog over it.

Hope you enjoy reading this blog for more interesting technical stuff connect me on LinkedIn 👇 👇

Thank You for reading !! 🤗 🤗

--

--

Aditya Raj

I'm passionate learner diving into the concepts of computing 💻