Building a Scalable WordPress Website with AWS EC2, RDS, and Apache Webserver

Naveen paluri
6 min readAug 1, 2023

--

What is WordPress ?

WordPress (WP, WordPress.org) is a free and open-source content management system (CMS) written in PHP and paired with a MySQL or MariaDB database. Features include a plugin architecture and a template system, referred to within WordPress as Themes. WordPress was originally created as a blog-publishing system but has evolved to support other web content types including more traditional mailing lists and forums, media galleries, membership sites, learning management systems (LMS) and online stores.

To function, WordPress has to be installed on a web server, either part of an Internet hosting service like WordPress.com or a computer running the software package WordPress.org in order to serve as a network host in its own right.

WordPress

What is Amazon RDS ?

Amazon RDS is a service which provides database connectivity through the Internet. RDS makes it very simple and easy to set-up a relational database in the cloud.

Instead of concentrating on database features, you can concentrate more on the application to provide high availability, security, and compatibility. RDS is a fully managed RDBMS service.

Benefits of Amazon RDS

Database Engines

There are six database engines which RDS provides, and they are:

  • Amazon Aurora
  • PostgreSQL
  • MySQL
  • MariaDB
  • Oracle Database
  • Microsoft SQL Server

Task Overview

🔅 Create an AWS EC2 instance

🔅 Configure the instance with Apache Webserver.

🔅 Download PHP application name “WordPress”.

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

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

Task Description

Let’s Begin the Task !!

Pre-requisites

  • Must have account on aws

Now we are ready to go ..

Step 1 : Create an AWS EC2 instance

Login to AWS Account.

Go to EC2 Dashboard ->> instances ->> Launch Instance

Click on Launch Instances

a) Select an AMI. Here I am selecting Amazon Linux 2 AMI.

Select AMI

b) Click next and Select the Instance Type. I’ll go for default one.

Select Instance Type

c) Configure Instance Details

Instance Details

d) Add Storage

Add Storage

e) Add Tags

Here we can create multiple tags like name, env etc. These tags are helpful to specify the instance.

Add Tags

f) Configure Security Group — Here I am adding one more rule for HTTP and allowing everyone to connect with the instance.

Note: It is not a good practice to allow everyone. We must create custom rules for the security of our instances.

( I have done this just for the demo )

Add Security Group

g) Review and Launch

Now, If we want to connect with this instance using the ssh protocol we need a key so here I am attaching an existing key. You can create a new one.

Attaching key

Here we can see, the instance is up !!

Instance launched

So the step 1 is done. Now move to the step 2 ..

Step 2 : Configure the instance with Apache Webserver

Let’s connect with the instance. There are so many ways to connect with the instance

  1. Using the browser
  2. Using ssh
  3. Using the software like putty etc.

Here I am using the first way. You can choose any one of the above.

Connect to the instance

Note: All the images do not provide this option to connect.

Currently we login as ec2-user. This user doesn’t have the admin power so to switch with root user, run the below command

sudo su -

Let’s Configure Apache Webserver !!

a) Install the Software

yum install httpd -y

b) Start the service and make it permanent

systemctl start httpd
systemctl enable httpd

Here we can see, it is successfully configured

Home Page of Apache webserver

Step 3 : Download PHP application name “WordPress”.

Requirements

  • PHP version 7.4 or greater.
  • MYSQL version 5.6 or greater OR MariaDB version 10.1 or greater.
  • HTTPS support
  1. Install PHP

To install php on Amazon Linux 2, we have to first install amazon-linux-extras package. ( By default, it is installed )

yum install -y amazon-linux-extras

Enable PHP 7.4 package

amazon-linux-extras enable php7.4

Now install PHP packages from the repository.

yum clean metadata yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap}

We can see the installed version of PHP using the below command

php -v

2. Download and extract the software

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

Download and extract the software

3. Upload the WordPress files in the root directory of webserver

Note: Here I am using Apache webserver so the root directory of the webserver is /var/www/html

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

WordPress is installed !!

We can check it by go to the url

http://<public_ip_of_server>/wp-admin/install.php

Successfully Installed

Here it will ask for the Database Information so we need to create a DataBase.

I am creating MYSQL Database using AWS RDS, you can use MariaDB or other databases also as per the requirement.

Step 4: Setup a MySQL server using AWS RDS service using Free Tier.

Go to AWS RDS Service →> Create Database

AWS RDS

Select MariaDB Engine

Different Engines

Templates ->> Free Tier ( You can select as per your requirement )

Settings ->> Set the Database name, Database User Name and the password

DB Info

Note: Whatever password you set for database, it should be remembered. As we need it in the future.

Give database a name !

  • Public Accessibility — yes
  • Security Group — AllowAll ( You can customize it )

I Go for the default settings and create the Database for this task.

Database

Our database is created. We’ll use this endpoint to connect with wordpress.

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

DB Info

Or we can manually write these information in the wp-config-sample.php file and rename this file with wp-config.php

mv wp-config-sample.php wp-config.php

Set Some Basic Information and click on the Installation.

After Successfully Login you will see the Dashboard of WordPress

Dashboard

Now we can write the blogs and post them.

Test Blog

I hope you find this Article is helpful

--

--