How to Set Up WordPress on AWS EC2 and RDS

Abhinav Shreyash
6 min readAug 3, 2023

--

Here is a point wise demonstration of what i am going to demonstrate in this medium post for all of you who are patient enough to spare some of your precious time (For which i am deeply grateful). -

  1. Create an AWS EC2 instance.
  2. Configure the instance with Apache Webserver.
  3. Download the PHP application named “WordPress”.
  4. Set up a MySQL server using AWS RDS service using Free Tier, as WordPress stores data at the backend in a MySQL Database server.
  5. Provide the endpoint/connection string to the WordPress application to make it work.

But Guys for going through my demonstartiona and for performing this tutorial you will be needing an aws Free Tier account( a paid will be a blessing though ) .

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 !!

Step 2 : Configure the instance with Apache Webserver

Let’s connect with the instance. There are 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 approach.)

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

a) Enable PHP 7.4 package

amazon-linux-extras enable php7.4

b) 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}

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

php -v

  1. Download and extract the software

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

tar -xzvf latest.tar.gz

Download and extract the software

2. 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 )

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

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.

Thank you for taking the time to read this article. Your time is truly appreciated. 😊

--

--