Deploy WordPress with Amazon RDS

In today’s article, we will learn how to set up a WordPress site on Amazon EC2 to run a blog. WordPress requires a MySQL database to store its data. For this lab, we will use Amazon RDS for MySQL to run your MySQL database.

So before the start, let me first write down the steps…


  • Create a MySql Database with Amazon RDS.
  • Creating an EC2 Instance.
  • Configuring RDS Database to allow access to specific entities.
  • Configuring WordPress on EC2.
  • Provide the endpoint/connection string to the WordPress application to make it work.

1. Create a MySql Database with Amazon RDS:

Database maintenance for your WordPress site is critical and also difficult. Your database instance holds all of your important data for your WordPress site. If the database goes down, your website may go down with it, and you could even lose your data. When setting up a WordPress site, you want to stay focused on designing your page and generating your content, not worrying about database performance and backups.

Amazon RDS for MySQL helps with both of these problems. Amazon RDS for MySQL is a managed database offering from AWS. With Amazon RDS for MySQL, you get:

● Automated backup and recovery so that you won’t lose data in the event of an accident;

● Regular updates and patches, keeping your database secure and performant;

● Easy installation with smart default parameters.

These features allow you to get a fast, reliable database without requiring specialized database knowledge. You can get on your way faster and start building your website.

Click the Create database button to get started.

  • Now the first step is to choose Engine Options we want to choose. Here I select MySQL, as Wordpress uses MySql.
  • In the template section, I choose AWS Free Tier as I doing it for only learning purpose.
  • In the Settings section, enter wordpress as your DB instance identifier. Then specify the master username and password for your database.
  • In the Connectivity Section, Choose same VPC where you launch your EC2 instance later. I also don’t want to give Public Access to my Database, So I choose No.
  • I also created one new VPC Security Group which we use later.
  • Finally, RDS provides a number of additional configuration options to customize your deployment. You need to make one change in this area. Click on the Additional configuration line to expand the options.
  • Set the initial database name to wordpress. This will ensure RDS creates the database in your MySQL instance upon initialization. You will use this database name when connecting to your database.
  • Finally, Click on Create Database Button to create your database.

Now, you see this screen that shows that your database is successfully created.

2. Create an EC2 Instance:

To create your EC2 instance, go to Amazon EC2 in the AWS console. Click the button that says Launch instance to open the instance creation wizard.

  • Select the AMI which you want. I’m choosing Amazon Linux 2 AMI here.
  • Choose an Instance type.
  • In Security Group, Allow two ports for SSH and HTTP.
  • It is now time to launch your EC2 instance. Click the Launch button to create your EC2 instance. Attach one key with EC2 instance so that I can login through SSH later.

Now we will configure our RDS database to work with our EC2 instance.

3. Configuring RDS Database:

Till now, we create EC2 instance and RDS Database. Now we need to configure RDS Database to allow access to specific entities.

In the previous step, we created security group rules to allow SSH and HTTP traffic to your WordPress EC2 instance. The same principle applies here. This time, you want to allow certain traffic from your EC2 instance into your RDS database.

  • For configuring this, Go to the RDS page and Click on the Database which we create earlier.
  • Click on VPC Security Group and Choose Security Group.
  • Now, Click on Edit Inbound Rules and Choose same security Group which we apply to WordPress EC2 Instance.

After you click, it will fill in the security group ID. This rule will allow MySQL access to any EC2 instance with that security group configured.

  • Finally, Click on Save Rules Button.

4. Configuring WordPress on EC2 Instance:

  • First I explain how to do it manually, after that we do it by using a script.

SSH your EC2 instance to do configuration.

  • Installing the Apache WebServer and start the service.
yum install httpd -y
systemctl enable --now httpd
  • Edit httpd configuration file:
vim /etc/httpd/conf/httpd.confAllowOverride All
  • Install MySql and php software:
amazon-linux-extras install php7.2 -y
yum install mysql -y

Now, Download the WordPress software and set up the configuration.

  • First, download and uncompress the software by running the following commands in your terminal:
tar -xzf latest.tar.gz
  • Now, move WordPress directory to RootDirectory(/var/www/html) of web server and provide write access to apache user so that it can create or modify any file if it needs…
mv wordpress /var/www/html
chown -R apache: /var/www/html/wordpress

Now everything is setup only we need to provide endpoint/connection string to the WordPress application to make it work.

We have one more way to do WordPress setup on EC2 instance by providing userdata using a script. By this way, we can automate the wordpress setup.

  • For this, While launching EC2 instance, in Configure Instance Details, provide userdata.

GitHub Link for code…

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

On Browser…


Click on Let’s Go button and Fill the Information, provide Database Endpoint in Database Host.

On Clicking Submit Button…

Click on Run The Installation and Filll all the details…

After that, Finally my site is ready to write Blog :)

Hope you find this article useful :)

Thanks for Reading…😊

Feel free to connect on linkedin…😊

Tech Enthusiasts, Passion to learn and share