Configure WordPress on ec2-instance using AWS RDS Service

Mohd Sabir
6 min readJan 12, 2021

--

In this blog we are gonna to discuss how to launch WordPress application in AWS ec2 instance and connect with RDS Database

What is WordPress?

WordPress is a free and open-source content management system (CMS) written in PHP and paired with a MySQL or MariaDB database. it is web publishing software you can use to create your own website or blog.

What is AWS RDS?

Amazon Relational Database Service (Amazon RDS) makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while automating time-consuming administration tasks such as hardware provisioning, database setup, patching and backups. It frees you to focus on your applications so you can give them the fast performance, high availability, security and compatibility they need.

Task Description:-

  • 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.

Let’s start doing our task:-

Create an AWS EC2 instance:-

Login to your AWS management console

After Login click on ec2 then click on “Launch Instances” after it select your configuration like AMI , Instance type , Security Group etc.

here I am using Amazon Linux 2
Instance type I am using t2.micro

Here I am allowing all traffic from anywhere but it is not good for security , You can customize it as per your your requirement

Take a review , attach the key and launch it.

Now our instance launch properly let’s move for next step

Configure the instance with Apache Webserver:-

To configure the apache webserver we have to login inside our instance let’s do it

for login We use SSH

finally we login inside our system

Now in our system we have to install multiple packages like “wget” “tar” “httpd” “php-mysqlnd” “php-fpm” and “php7.3”

Let’s discuss about all these

wget : The wget command is a command line utility for downloading files from the Internet.

tar: The tar command is used to compress a group of files into an archive. The command is also used to extract, maintain, or modify tar archives.

php-mysqlnd: The MySQL native driver for PHP (mysqlnd) is a drop-in replacement for the MySQL Client Library (libmysql) for the PHP script language.

PHP-FPM:- PHP-FPM (an acronym of FastCGI Process Manager) is a hugely-popular alternative PHP (Hypertext Processor) FastCGI implementation.

Now let’s install all these in our ec2-instance

now we will install PHP version 7.3

run this cmd

we have already install httpd software for apache webserver let’s start the services of it

for starting httpd services
to start the service permanently
to check status

Now our webserver is working fine let’s go to document root of webserver and download the PHP application

now we are in document root of webserver

to download the PHP application we use wget command

finally it’s downloaded

PHP application downloaded but it is a tar file we have to extract it

for extracting we use tar command

for extracting

after extract they will create one directory name “wordpress”

you can see

now our webserver is configure properly or not let’s check it

paste your ec2-instance ip on your browser

http://ip_of_ec2_instance

wow it’s working good

Let’s test our PHP application

http://ec2-instance-ip/wordpress

amazing it is also working fine

Now let’s move to another step

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.

Let’s create a database for wordpress

  • Go to AWS management console and search for RDS
  • After open RDS click on “create database”

and now choose your configuration step in my case it is

I am using Mysql
I am using mysql version 5.6
I am using free tier but you can choose as per your requirement
setting up username & password for database
I am allowing my db publically you can keep it private
I am selecting security group “fordb” which is created by me , you can create your security and attach with this

after selecting your configuration click create database

After some time our Database is ready let’s connect our database with endpoint

In local system run the command

“mysql -h endpoint_of_database -u username -p “

you can check your endpoint after going to your database
connected successfuly

database created now we use this database in our PHP application

http://ec2-instance-ip/wordpress

click on let’s go
update your database detail & submit

In my case it is

wow it’s connected to my database , one thing I have to do , that I need to update the wp-config.php file manually , Let’s do it then we will install our wordpress

it’s done

Now we will install the wordPress

Thanks for reading…

--

--

Mohd Sabir
Mohd Sabir

Written by Mohd Sabir

DevOps Enthusiastic || Kubernetes || GCP || Terraform || Jenkins || Scripting || Linux ,, Don’t hesitate to contact on : https://www.linkedin.com/in/mohdsabir

No responses yet