Integrating WordPress With RDS On AWS Cloud

In this article, you will find how to launch a WordPress application on the top of the ec2 instance on AWS cloud and how to integrate it with the Relational Database Service (RDS) of AWS Cloud.

Before starting, let us have a quick overview of the technologies used in this article:

WordPress is known to be the simplest and one of the most popular ways to create your own blog or website.

Did you know WordPress powers over 40.0% of all the websites on the Internet?

Yes — more than one in four websites that you visit are likely powered by WordPress.

RDS is one of the fully managed services of AWS cloud. Using RDS, you can set up, operate, and scale a relational database on the top of the AWS cloud.

And the most interesting part is that you do not need to manage anything about this database, everything will be managed by AWS itself. You have to launch the database by telling your requirements.

Task Details:

🔅 Create an AWS EC2 instance

🔅 Configure the instance with Apache Webserver.

🔅 Configure WordPress on ec2 instance.

🔅 WordPress stores data at the backend in the MySQL Database Server. Therefore, you need to set up a MySQL server using AWS RDS service using Free Tier.

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

  • The very first step is to launch an ec2 instance on the AWS cloud.

I have used the Amazon Linux 2 AMI, you can use any AMI of your choice. However, some commands may vary in the process with a different AMI.

  • The next step is to log in to the instance and set up the Apache WebServer and WordPress.

I have used putty to do SSH to the instance running on AWS cloud. After connecting to the instance, we require PHP and Httpd (Apache WebServer) software.

To install httpd, use the above command:

yum install httpd -y

  • The next step is to install PHP.

Note that not every version of PHP is not compatible with all the versions of the Database. Here, I will be using the latest version of MySQL for my database server. And Php version7.3 works fine with it.

To install Php7.3, I have used the special command of Amazon AMI:

amazon-linux-extras install php7.3 -y

For other AMIs, this command might vary to install version7.3 of PHP.

  • After both the packages have been installed, the next step is to download WordPress.

Use the above command to do so:

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

In case, if the instance does not have the wget command, use the above command to install it first:

yum install wget -y

  • Next step: Extracting the downloaded package.

Use the above command to do so:

tar -xzf latest.tar.gz

After extracting, a new directory named ‘wordpress’ will be created.

  • Now, we have to copy the entire content of this folder to the default document root of the Apache WerServer i.e., to the /var/www/html directory.

Use the above command to do so:

cp -rf wordpress/* /var/www/html/

  • The next step is to start the service of the webserver.

Use the above command to do so:

systemctl enable httpd - -now

This command will start the service and make it permanent at the same time.

And now if try to access the web server, it will ask for the details of the database server:

So, let us now set up the database for this WordPress. And we will use the RDS service of AWS to set up our database server.

Go to AWS RDS and click on ‘Create Database’

Database creation method: Standard

I am going to use the MySQL engine, you can use other options as well.

I am using one of the latest versions of MySQL, version 8.0.21. And I will be using the ‘Free Tier’ template to launch the database.

Next step: give the database instance name, master username and the master password.

Keep all the other setting as they are, we will be using default VPC, subnets, instance types, etc.

Allow public access to the database by selecting the ‘Yes’ option:

If you give the public access to the database, a public IP will be assigned to it and you can connect to the database from anywhere in the world. But if you are accessing this database from one of the amazon instances only, you can decide not to give it public access. By default, all the amazon instances will have internal connectivity in the same VPC.

In the additional configuration section, create a database by providing a name to it.

And the RDS configuration has been finished. Click on create the database and wait for the process to finish. Once the database is created, click on the database and it will give an endpoint. We will use this endpoint to connect our WordPress with the database server.

And now, we have to provide these database details to out WordPress:

Go to the WordPress URL and click on “Let’s go!”, and on the next page, provide the database details such as database name, username, password, and database host i.e, Endpoint.

And then, click on Submit.

Now, here comes the interesting part. On the next page, you will get a screen like this:

It says that it was unable to write to the wp-config.php file and it asks us to create the wp-config.php file in /var/www/html/ location and enter the given content in that file.

Why did this error come and what does it mean? Let me try to clear this out.

Whatever database details we entered just now, we need to keep this information in some file so that whenever our WordPress wants to connect to the database, it can pick the information from that file. And here, WordPress uses wp-config.php named file to store and pick information.

Now, why WordPress did not create this file and why it asked us to create the file on its behalf?

Apache Webserver creates and uses an Apache user behind the scene to do certain things. Apache is a service user and it is the one that has to copy the code inside the wp-config file at /var/www/html location by creating it first. But here, we have not given any permissions to the apache user to do any changes in the /var/www/html location. Because it is not always recommended to give extra permissions to a service user.

But still, if we want that the configuration process should be done by Apache user and we do not have to do any manual configuration, here we have to provide the required permissions to the Apache user.

Use the following commands to do so:

chown -R apache:apache /var/www/html/

And in case, if any issue appears with SELinux, you can disable Selinux or you can set the context of /var/www/html to httpd_sys_rw_content_t.

After running the above commands, go back, again enter the database details and click on Submit.

And this time you will see that the wp-config.php file creation and its configuration is done automatically.

Click on ‘Run the Installation’, set up your profile by providing the personal details and after login, you are all set to use your own WordPress for creating exciting blogs.

And hence, all the requirements of the task have been fulfilled.

So, that was all about this blog. I hope you liked the above article.

Waiting for your valuable feedback/suggestions😀

See you in the next article with other exciting tasks.🤗

Meanwhile, you can also follow me Medium and LinkedIn as well for similar exciting contents.

I am an active learner who likes to challenge every problem with a can-do mindset in order to make any idea a reality.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store