Table of contents
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 tofocus
on your applications so you can give them thefast performance
,high availability
,security
andcompatibility
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 theUbuntu Server 20.04 LTS (HVM), SSD Volume Type
AMI.
- Step-02: Select the
t2.micro
instance type and key pair.
- Step-03: Create a
new security
group and add the followingrules
to it.
- Step-04: We have created our EC2 instance.
Now let's create an RDS
for our WordPress site.
- Step-01: Search for
RDS
in theAWS services
and selectRDS
.
- Step-02: Click on
Create database
.
- Step-03: Select
MySQL
as theDatabase creation method
.
- Step-04: Select Engine Version and then Select
Free tier
inTemplates
.
- Step-05: Now we will set the
DB instance identifier
andMaster username
andMaster password
.
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.
- Step-08: Configure the Additional Setting by adding a name to it.
- Step-09: Click on
Create Database
and check the dashboard for your database.
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.
- 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.
- Go inside the Security Group > Click on Inbound rules > Click on Edit inbound rules.
- Click on it and add the source as the Security group we created earlier while creating an
EC2 instance
and click on Save rules.
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.
- Step-02: Add the
AmazonRDSFullAccess
policy to the role.
- Step-03: Give a name to the role and create the role and review it.
- Step-04: Now check whether the role is created or not.
- Step-05: Now go to
EC2
and select theInstance
and click onActions
>>Instance Settings
>>Modify IAM Role
.
- Step-06: Select the role which we created previously and click on
Save
.
- Now let's connect to our EC2 instance using SSH.
- Now let's install MySQL-client in our EC2 instance.
sudo apt update
sudo apt-get install mysql-client
mysql --version
- 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.
- 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
- 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
- Now let's Install a Server where we can Host our Website for that we have used Apache Server.
sudo apt update
sudo apt install apache2
- Now let's check the status of the Apache server. Open the Public IP of your
EC2 instance
in the browser.
- 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
After this let's Download and COnfigure the WordPress.
wget command is used to download WordPress.
wget https://wordpress.org/latest.tar.gz
- Now let's extract the tar file.
tar -xvzf latest.tar.gz
- After Extracting
change the directory
to WordPress and create a copy of the defaultconfiguration file
which is (wp-config-sample.php).
cd wordpress
cp wp-config-sample.php wp-config.php
- 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.
Now let's edit the Authentication Unique Keys and Salts. Copy the below API code and paste it into the wp-config.php file.
- 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
- Now let's copy the WordPress files to the Apache root directory.
cd ..
sudo cp -r wordpress/* /var/www/html/
sudo systemctl restart apache2
- To check whether the website is running or not open the Public IP of your
EC2 instance
in browser.
http://<public-ip>/wp-admin
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.