Deploying a WordPress site over AWS using RDS

Divya Kurothe
Level Up Coding
Published in
4 min readJun 12, 2021

--

WordPress is a highly popular content management system (CMS) that is used for over 30% of all sites on the internet. It is most commonly used for blogs but can also be used for running e-commerce sites, message boards, and many other popular use cases.

MySQL is an open source relational database management system (RDBMS) that can be easily implemented and managed either on-premise or via the cloud through a hosting provider.

With Amazon RDS for MySQL, we 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 and easy installation with smart default parameters.

In this blog, we’ll see how to configure a WordPress installation using Amazon RDS for MySQL. To configure this WordPress site, you will create the following resources in AWS:

  • An Amazon EC2 instance to install and host the WordPress application;
  • An Amazon RDS for MySQL database to store your WordPress data.

Firstly, we need to launch an AWS EC2 instance as follows:

ec2 launch

I’m here launching the instance with all the default configuration, allowed all traffic in ‘configuring security section’ (which is indeed not a good practice in real use case scenarios), selected a key pair and then launched my ec2 instance.

WordPress (the software) is a web application. To run WordPress on any machine, we’ll need to install Apache, PHP, and MySQL. So, once the instance is launched we can connect to the instance and do some configurations there. For the switch to root account (which is again not a good practice) using sudo and run the following commands there:

$ yum install httpd -y
$ yum install mysql -y

WordPress is written in PHP, we need to install PHP on the instance using:

$ amazon-linux-extras enable php7.4
$ yum install php-cli php-pdo php-fpm php-json php-mysqlnd

Then go inside document root, /var/www/html and download the WordPress file and unzip it.

$ wget http://wordpress.org/latest.tar.gz
$ tar -xzf latest.tar.gz

At last, start the httpd service and make it permanent:

$ systemctl start httpd
$ systemctl enable httpd

WordPress uses MySQL to store this content, so here we are using Amazon RDS for MySQL. You can create multiple WordPress installations that connect to a single MySQL instance on RDS, allowing you to scale your site horizontally.

Here, I’m using a standard create and free tier for launching MySQL. And I have provided a master username and password along with the initial database name(in additional configuration).

Now, we can login to our database through EC2 instance using the command :

$ mysql -h <endpoint> -u <username> -p

Enter the IP address of your ec2-instance in your browser to open the WordPress configuration menu by entering initial database name, username, password and DNS endpoint of the database.

Now after submitting you can either edit the content of wp-config-sample.php in /var/www/html folder and update the it by providing username, password, database name, etc or directly overwrite it’s content by copying the content shown in WordPress page. And after doing this rename the file as wp-config.php and then click ‘run installer’ and restart httpd services using the command:

systemctl restart httpd

Now it’s time for the fun part — go play with your new site. Configure the design, add pages and posts, and start getting users to your site.

That’s all folks… Thankyou for reading :)

This task was done in collaboration with Prithviraj Singh ergo I would like to thank him for his constant help and guidance. ^-^

--

--