DEV Community

Revathi Joshi for AWS Community Builders

Posted on

Create a Wordpress site Using EC2 and Amazon RDS

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 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)?

Steps for implementation to this project:

1. Create EC2 Security Group - Web-Access

Image description

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

Image description

3. Create an EC2 webserver

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

  • 1.

Image description

  • 2. security details

Image description

  • 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
Enter fullscreen mode Exit fullscreen mode
  • summary details of EC2instance

Image description

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

  • Connectivity and Security

Image description

  • security group rules

Image description

  • 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

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

Image description

Image description

Image description

  • Install WordPress

Image description

  • Login

Image description

  • Welcome to Worpress

Image description

Image description

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.

Top comments (0)