How to launch Wordpress on AWS EC2 & Connecting it to MySQL RDS database.

Amazon Web Services (AWS):-

Gaurav Khore
6 min readJan 11, 2021

Amazon Web Services (AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis.

These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools.

Amazon Relational Database Service (Amazon RDS):-

Amazon Relational Database Service (or Amazon RDS) is a distributed relational database service by Amazon Web Services (AWS). It is a web service running “in the cloud” designed to simplify the setup, operation, and scaling of a relational database for use in applications.

Administration processes like patching the database software, backing up databases and enabling point-in-time recovery are managed automatically.

RDS MySQL:-

MySQL is the world’s most popular open source relational database and Amazon RDS makes it easy to set up, operate, and scale MySQL deployments in the cloud.

With Amazon RDS, you can deploy scalable MySQL servers in minutes with cost-efficient and resizable hardware capacity.

Wordpresss:-

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.

Lets see a example of how to connect wordpress site launched on the Amazon EC2 instance with the relational database mysql provided by the Amazon RDS service.

Task:-

đź”… 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.

Solution:-

Step 1:- Create an AWS EC2 instance:-

For creating a AWS instance use the ami “Red Hat Enterprise Linux 8 (HVM), SSD Volume Type — ami-0a9d27a9f4f5c0efc” and in the security group give the inbound rules for the httpd server i.e prot 80 and also for ssh i.e prot 22 and for wordpress i.e 3306 prot.

Also mark the subnet name because we have to launch the aws rds mysql database in the same subnet so that the ec2 instance and the database have proper connectivity.

For launching ec2 instance using cli go for the following link:-

Step 2:-Configure the instance with Apache Webserver:-

We are configuring the appache webserver because the wordpress site is based on php and html , so the wordpress site is only accsessible through the httpd port.

For installing the Apache webserver on the redhat8 ami use the below cmd:-

yum install httpd -y

Use the below cmd to start the httpd server and also permanently start the server by enabling httpd.

Step 3:-Install the prerequisite for the wordpress site hosting:-

We have to install some software like maridb , php , php mysql connection and some more, so that the wordpress site work properly.

For installing the prerequisite use the below cmd:-

also install php,

Step 4:- Download php application name “WordPress”.:-

We can download wordpress using the :-

Now we have unzip the wordpress.tar.gz file and after unzipping we have to copy the “wordpress” folder extracted during unzipping to the “var/www/html” folder. For that use the below cmds:-

Step 5:- Give appache user the sudo access :-

Step 6:-After installing wordpress we can access the wordpress site using the ip of the base os (in our case public ip of the ec2 instance).

(It give error on submit because we have to add the databse to the wordpress)

Step 7:- 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.:-

For configuring the mysql database on the RDS service of the AWS we have to do:-

Go to AWS RDS console and than create database,

Provide the database name with the version.

Provide the database name , username , password to the database.

As you have selected free tier it has bydefault selected the db.t2.micro instance type so no need to make changes here.

Enable the storage autoscaling so that in future you van increase the storage of the database.

Gove public access to no so that only the ec2 instance launch in the same vpc and the same subnet can access the database. Also provide the security group.

After that launch the database,

After launching the database we have to create the database name so that the wordpress data can be stored in the particular database for taht we can access the database by the above cmd and create the database .

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

endpoint url is the “endpoint” given by the mysql database launched on the rds .

We can give the connection string to the wordpress while accessing it from the ip of the instance i.e,

After providing the information to the wordpress just submit it and than we can access the wordpress site, i.e

Thanks for reading…….

--

--