Day 45: Deploy WordPress website on AWS.

Day 45: Deploy WordPress website on AWS.

Today I have covered,

  • How to Connect the AWS EC2 instance and AWS RDS using IAM Roles?

  • How to Deploy a WordPress website on the Server using AWS?

Over 30% of all websites on the internet use WordPress as their content management system (CMS). It is most often used to run blogs, but it can also be used to run e-commerce sites, message boards, and many other popular things. This guide will show you how to set up a WordPress blog site.

Overview

As WordPress requires a MySQL database to store its data ,create an RDS as I did on Day 44.

To configure this, 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.

  • Setup the server(I used Apache Server) and post your new WordPress app.

AWS EC2 Instance?

  • Amazon Elastic Compute Cloud(Amazon EC2) is a web service that provides secure, resizable computing capacity in the cloud. It is designed to make web-scale cloud computing easier for developers. Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction.

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.

Apache Server?

  • The Apache HTTP Server, colloquially called Apache, is a free and open-source cross-platform web server software, released under the terms of Apache License 2.0. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation.

IAM Role?

  • An IAM role is an IAM identity that you can create in your account that has specific permissions. An IAM role is similar to an IAM user, in that it is an AWS identity with permission policies that determine what the identity can and cannot do in AWS.

Task-01

  • Step-01: Let's create an EC2 instance for our WordPress site on AWS.Give it a name and select the Ubuntu Server 20.04 LTS (HVM), SSD Volume Type AMI.

imageedit_7_6805979323

  • Step-02: Select the t2.micro instance type and key pair.

imageedit_3_5707263619

  • Step-03: Create a new security group and add the following rules to it.

imageedit_12_8507538908

  • Step-04: We have created our EC2 instance.

Screenshot from 2023-07-21 11-52-51


Now let's create an RDS for our WordPress site.

  • Step-01: Search for RDS in the AWS services and select RDS.

Screenshot from 2023-07-15 21-16-14

  • Step-02: Click on Create database.

imageedit_2_4092586013

  • Step-03: Select MySQL as the Database creation method.

Screenshot from 2023-07-15 21-18-32

  • Step-04: Select Engine Version and then Select Free tier in Templates.

Screenshot from 2023-07-15 23-11-13

  • Step-05: Now we will set the DB instance identifier and Master username and Master password.

imageedit_17_9069323176

  • Step-06: Let the instance and storage type by default and click on Create database.

  • Step-07: Now check the connectivity of the database by clicking on "Don't connect to an EC2 instance" and VPC is the default.

Screenshot from 2023-07-21 11-48-09

  • Step-08: Configure the Additional Setting by adding a name to it.

Screenshot from 2023-07-21 11-48-22

  • Step-09: Click on Create Database and check the dashboard for your database.

Screenshot from 2023-07-21 14-58-56


Now let's configure the AWS Relational Database Service or RDS with our EC2 instance.

  • By giving the network connectivity to our EC2 instance.So Open AWS RDS.

Screenshot from 2023-07-21 14-58-56

  • In the RDS console > Select the database > Click on Connectivity & security > Select VPC security groups > Click on Edit > Select the security group > Click on Save.

imageedit_20_3810322249

  • Go inside the Security Group > Click on Inbound rules > Click on Edit inbound rules.

imageedit_22_3880708883

  • Click on it and add the source as the Security group we created earlier while creating an EC2 instance and click on Save rules.

imageedit_26_8964083573


Now let's create an IAM Role for our EC2 instance to access the RDS instance.

  • Step-01: Go to AWS Console >> Services >> IAM >> Roles >> Create Role and also select EC2 as the service.

Screenshot from 2023-07-17 09-56-25

  • Step-02: Add the AmazonRDSFullAccess policy to the role.

Screenshot from 2023-07-17 09-56-54

  • Step-03: Give a name to the role and create the role and review it.

Screenshot from 2023-07-17 09-58-06

  • Step-04: Now check whether the role is created or not.

imageedit_4_5255382338

  • Step-05: Now go to EC2 and select the Instance and click on Actions >> Instance Settings >> Modify IAM Role.

Screenshot from 2023-07-17 12-48-50

  • Step-06: Select the role which we created previously and click on Save.

Screenshot from 2023-07-17 09-59-46


  • Now let's connect to our EC2 instance using SSH.

Screenshot from 2023-07-21 12-21-44

  • Now let's install MySQL-client in our EC2 instance.
sudo apt update
sudo apt-get install mysql-client

Screenshot from 2023-07-21 12-23-37

mysql --version

Screenshot from 2023-07-21 12-23-58


  • Go to RDS Console > Open the Database you created > In the details of your Amazon RDS database, the hostname will be shown as the Endpoint in the Connectivity & Security section.

imageedit_28_6002623661

  • Here we are connecting the RDS Database with mysql-client in our EC2 instance.
export MYSQL_HOST=<your-endpoint>
#export MYSQL_HOST=wordpress.caxt8wmsdc7r.ap-south-1.rds.amazonaws.com

Screenshot from 2023-07-21 12-26-16

  • Now let's fill in the Master username and Master password which we created while creating the RDS instance so that it verifies and give access to mysql.
mysql --user=<user> --password=<password> wordpress
#mysql --user=admin --password=Rohit8329$ wordpress

Screenshot from 2023-07-21 12-27-23


  • Now let's Install a Server where we can Host our Website for that we have used Apache Server.
sudo apt update

Screenshot from 2023-07-21 13-28-16

sudo apt install apache2

Screenshot from 2023-07-21 13-28-41

  • Now let's check the status of the Apache server. Open the Public IP of your EC2 instance in the browser.

Screenshot from 2023-07-21 13-29-25


  • Now let's create a Database for our WordPress site.
CREATE DATABASE wordpress;
CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress';
FLUSH PRIVILEGES;
Exit

Screenshot from 2023-07-21 13-27-43

  • After this let's Download and COnfigure the WordPress.

  • wget command is used to download WordPress.

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

Screenshot from 2023-07-21 13-30-52

  • Now let's extract the tar file.
tar -xvzf latest.tar.gz

Screenshot from 2023-07-21 13-31-21

  • After Extracting change the directory to WordPress and create a copy of the default configuration file which is (wp-config-sample.php).
cd wordpress
cp wp-config-sample.php wp-config.php

Screenshot from 2023-07-21 13-33-56

  • Now let's edit the wp-config.php file.
vim wp-config.php
  • First, We will edit the database name and database user and database password.

Screenshot from 2023-07-21 16-03-12

Screenshot from 2023-07-21 16-03-25

  • Now let's Deploy the WordPress site, but before that, we need to install some dependencies.
sudo apt install php libapache2-mod-php php-mysql -y

Screenshot from 2023-07-21 13-37-03

  • Now let's copy the WordPress files to the Apache root directory.
cd ..
sudo cp -r wordpress/* /var/www/html/
sudo systemctl restart apache2

Screenshot from 2023-07-21 13-37-37

  • To check whether the website is running or not open the Public IP of your EC2 instance in browser.
http://<public-ip>/wp-admin

Screenshot from 2023-07-21 13-38-36

Thus we have successfully deployed our WordPress site and also connected it with the RDS instance.

NOTE: After Checking the website Delete the EC2 instance and RDS instance to avoid unnecessary charges.


Happy Learning :)

Did you find this article valuable?

Support DevOps by becoming a sponsor. Any amount is appreciated!