Create a Wordpress site Using EC2 and Amazon RDS
Tags: ec2, rds, securitygroup, wordpress
Published: 2023-08-10 22:14:37

In this article, I am going to demonstrate on how you create a Wordpress site using EC2 and MySQL RDS Database Instance.

***Amazon Relational Database Service (Amazon RDS)*** allows users to easily create, operate, and scale a relational database in the cloud. We are going to create an RDS database, install a web server and configure WordPress to connect to the RDS database. We will then run the final configuration through the web browser to complete the installation of wordpress site. 

Please visit my **[GitHub Repository for RDS_projects] (https://github.com/awsmine/RDS_projects)** on various topics being updated on constant basis.

_**Let’s get started!**_


# Objectives:

**1.** Create EC2 Security Group - Web-Access

**2.** Create RDS Security Group - RDS-SG

**3.** Create an EC2 webserver

**4.** Create RDS Database

**5.** Complete Wordpress Installation and Test

# Pre-requisites:
- AWS user account with admin access, not a root account.


# Resources Used:

***[What is Amazon Relational Database Service (Amazon RDS)?](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html)***

# Steps for implementation to this project:

## 1. Create EC2 Security Group - Web-Access

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/twm2lvb8n0zn5l0imeol.png)

## 2. Create RDS Security Group - RDS-SG

On the EC2 Dashboard, In the left-hand navigation menu, under Networks & Security, click Security Groups - Create Security Group. Security group name - RDS-SG, default VPC, Click the Inbound rules tab, Click the Edit inbound rules button, Click the Add rule button, For the new rule, from the Type dropdown menu, select MYSQL/Aurora, In the dropdown menu to the right of the Source column for the new rule, find and select the ***`Web-Access`*** security group, Click Save rules.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gy6yj9kqpg36kh6bx22f.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvafxu92qfnulx06d394.png)

## 3. Create an EC2 webserver

From the EC2 Dashboard, create an EC2 instance with the following parameters.

- 1.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8oaldljc6mzfgkarxsc.png)

- 2. security details


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/puz87j6ym1phsmalitiy.png)


- 3. userdata - Install Apache and Dependencies and Configure WordPress

```
#!/bin/bash
# Enter root access
sudo -s
# Update the os
yum update -y
# Install Apache server
sudo yum install -y httpd
# Install wordpress
sudo amazon-linux-extras install -y php7.2
# Install Wget
yum install wget -y
# Download MySQL Community
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
# Install MySQL
rpm -ivh mysql-community-release-el7-5.noarch.rpm
# Install MySQL Server
yum install mysql-server
# Install PHP-MySQL
yum install php-mysqlnd -y
# Enter html directory
cd /var/www/html/
# Create html file
echo "healthy" > healthy.html
# Download wordpress
wget https://wordpress.org/latest.tar.gz
# Extract the file
tar -xzf latest.tar.gz
# Coping the wordrpress to html folder
cp -r wordpress/* /var/www/html/
# Remove the folder
rm -rf wordpress
# Remove the file
rm -rf latest.tar.gz
# Give Permisson to the folder
chmod -R 755 wp-content
# Own the file and folders
chown apache:apache /var/www/html
# Check httpd config
chkconfig httpd on  
# Start the httpd service   
service httpd start
```

- summary details of EC2instance


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttckxsxgsdxuunwerof1.png)



## 4. Create RDS Database

On the Amazon RDS Console, Create database, ***`Standard create`***, Engine type - ***`MySQL`***, Templates - ***`Free tier`***, Under Settings, DB instance identifier - ***`database-1`***, Master username - ***`admin`***, Master password - ***`admin1234`***, Confirm master password - ***`admin1234`***, DB instance class - ***`db.t2.micro`***, Allocated storage - ***`20 GB`***, Storage autoscaling - ***`uncheck Enable storage autoscaling`***, Under Connectivity, select the existing VPC  ***`leave the Don't connect to an EC2 compute resource selected`***, ***`select the existing default VPC`***, Under VPC security group, select ***`RDS-SG`*** and remove the default security group, Under Availability zone ***`us-east-1a`***, Expand Additional configuration and, Monitoring - ***`Uncheck Enable Enhanced monitoring`***, under Initial database name, enter ***`rds`***,  Under Additional Configuration, Backup - ***`Uncheck Enable automated backups`***, Maintenance - ***`Uncheck Enable auto minor version upgrade`***, Deletion protection - ***`Uncheck Enable deletion protection`***, Take all defaults

- Create database



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fi4ugj1b2h324paj553.png)

- Connectivity and Security


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ccih5ma1arsshrprcmc8.png)

- security group rules


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p7lhuc5s0wkveasb8zol.png)

- Wait for 5-6 minutes to see the database created.

- copy and paster EC2 Public IP 34.229.105.66 on the web browser

- Installation of Wordpress is successful


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bc6965dvfrq9yfz6b5mz.png)


## 5. Complete Wordpress Installation and Test

- Enter the values to connect to the database - ***`rds`***

- database name - rds
- database host ---> database endpoint - ***`database-1.cgizjtuyxkda.us-east-1.rds.amazonaws.com`***



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6rsaaogtu1g3bhnbyg7.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6z5j7t4qpzw7k87ojqgg.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84n08ld0u6n95o55jsoj.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fkf04k7iqlv3s6ekylfy.png)

- Install WordPress


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2cluxc0uadynv7misr2t.png)

- Login



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sd2uo5n6mn4hq6pkspwz.png)

- Welcome to Worpress


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2qjy51gzviavumn85goo.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3n9jwcfk15gecp5gaglo.png)

## 6. Delete AWS Resources
- Delete the RDS database
- Delete EC2 instance


# 7. What we have done so far
We have successfully created a Wordpress site using EC2 and MySQL RDS Database Instance.