Launching WordPress on AWS with RDS
Tags: aws, mysql, wordpress, devops
Published: 2021-09-05 05:06:28

# USE-CASE
1. Create an AWS EC2 instance  
2. Configure the instance with Apache webserver
3. Download php application name "WordPress".
4. Setup a MySQL server using AWS RDS service using Free Tier as a backend
5. Provide the endpoint/connection string to the WordPress application to make it work

## Pre-requisite: 
1. AWS Account

### STEP 1 : Create an EC2 Instance
🔶 We need to launch an EC2 Instance on AWS which we will use to configure Apache Webserver and run WordPress.

🔶 Click on `Launch Instance`.

🔶 Select 'Amazon Linux` as a Instance Flavor.

![Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_07_48 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cf750g51p3g1crsjk787.png)
 
🔶 Select `t2.micro` as a `instance type`. It is free for eligible.
![Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_08_00 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/af4qde5o34ggtbb6d6a1.png)

🔶 Provide configuration details and click on `Add Storage`.
![Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_08_06 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcm5mrraeo5ndnkj0q7n.png)
 
🔶 Add `storage`. I will keep it default. And click on `Add Tag`.
![Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_08_20 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jarywbww9xy7slr907g2.png)

🔶 Add `tag` if you want. For this, click on `Add another tag`.
![Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_08_43 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kzd0hzveavwmty8o3hf.png)
🔶 After this click on `Configure Security Group`.

🔶 Click on `Add Rule`. I will allow `All traffic` to avoid any firewall issue. Then click on `Review and Launch`.

🔶 Attach `key pair` then Instance will launched successfully.

![Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_09_27 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8vvq77usiutd6px6whv.png)
![Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_09_57 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ibv8gdutzshum4xsc4q.png)

🔶 Click on `Instance ID`. You will get all the details of your created instance.

🔶 You will get `Public IP` and `Private IP` from this.
![Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_10_32 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h7jy6dzqyrkaaumzrbxy.png)

Now you can use `Public IP address` any Key to connect this Instance. You can use Putty(Recommended) or CLI Browser provided by Amazon to Connect Instance.

Lets go for Next to Configure the instance as Apache Webserver:

### STEP 2 : Configure the Instance with Apache Webserver

🔶 Here we are going to configure the `Apache Web Server` in Amazon Linux 2 Instance.

🔶 To run WordPress, we need to run a web server on our EC2 instance. The open source Apache web server is the most popular web server used with WordPress.
🔶 Install Apache Web Server.
````
sudo su -
yum install httpd -y 
```
🔶 Then we are Starting Webserver and Enable it Permanently.
```
systemctl start httpd

systemctl enable httpd
```

### STEP 3 : Installation and configuration of php software name `WordPress`
🔶 WordPress is a php Application, let’s install `php 7.2`.

🔶 With Amazon Linux 2, you can use the Extras Library to install application and software updates on your instances.
```
 amazon-linux-extras install -y php7.2
```
🔶 After that download WordPress file!
```
wget http://wordpress.org/latest.tar.gz
```
🔶 After download the "TAR" file "UNTAR" it.

```
tar -xvzf latest.tar.gz
```
🔶 Next you see `wordpress` name `dir` come up. So now you can copy all Content inside `wordpress folder` to Document Root `/var/www/html`.
```
cp -rf wordpress/* /var/www/html
```
##### Note: 
Make Sure where you download your `tar` file and where you `Untar` it.

### STEP 4 : Setup a MySQL server using AWS RDS service with Free Tier Account
🔶 Let’s now launch a MySql database using `Amazon RDS`.

🔶 Click on `Create Database`.
![RDS Management Console - Google Chrome 04-09-2021 10_16_24 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9o6013f3v5gsozxzzoag.png)
 
🔶 Choose `Standard Create` and `MySQL` as a engine option.
![RDS Management Console - Google Chrome 04-09-2021 10_16_55 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/412xa1rf8iwtwx3evupv.png)

🔶 Select Version `MySQL 8.0.20` and template as `Free tier`.
![RDS Management Console - Google Chrome 04-09-2021 10_17_14 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tz7jwakay9o39i2brny4.png)

🔶 Provide DB Instance name, Username & Password
![RDS Management Console - Google Chrome 04-09-2021 10_26_22 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qtqxdoq3jg186p48hs84.png)
 
🔶 Here this DB instance have No Connectivity to Internet. We will access it through EC2 Instance.
![RDS Management Console - Google Chrome 04-09-2021 10_23_51 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/utmybrrxb6ru9ojuq0wh.png)
![RDS Management Console - Google Chrome 04-09-2021 10_24_30 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fc74erj62llfcv1h1ol3.png)

🔶 Now after Launching this DB Instance `mydb` named Database will be created inside this DB server.
![RDS Management Console - Google Chrome 04-09-2021 10_25_20 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qak8y43nr5lbjuz3nf2.png)

🔶 Now click on `Launch Database`. It will take around 10 minutes.

🔶 Once the Database is available, click on `Connectivity & Security`. You will get `hostname` and `Port no.` there.
![RDS Management Console - Google Chrome 04-09-2021 10_36_48 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uuurfyjk2l72iowgxsc7.png)

### STEP 5 : Provide the Endpoint/Connection string to the WordPress Application
🔶 Go to the created EC2 Instances instance. In the Description below, find the `Public DNS (IPv4)` of your instance.

🔶 Enter this IP Address into your web browser. And type Enter.
![WordPress › Setup Configuration File - Google Chrome 05-09-2021 08_56_01 AM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kh7w8tkxrf1sefago6rg.png)

![WordPress › Setup Configuration File - Google Chrome 05-09-2021 08_56_08 AM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d10c8wlvnx13gogvkgco.png)

🔅 Provide Following Information:
🌀 Database Name: Provide Name of Database which created at time of launching DB!

🌀 Username: The username you given while launching DB Instance!

🌀 Password: Provide Password!

🌀 Database Host: Provide the ENDPOINT which you get from "wordpress-database"!

![(4) Launching WordPress on AWS with RDS _ LinkedIn - Google Chrome 05-09-2021 09_06_58 AM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4cdzq3tzeds4k6ggwf6l.png)

🔶 Now our WordPress is running on the AWS using AWS RDS as a service and in the backend it is using MySQL. 
Let's check from CLI.
Use command
```
# mysql -h <endpoint_url> -u <username> -p
```
And provide our password.
![root@ip-172-31-45-40_~ 05-09-2021 09_19_29 AM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjamk2n50v8rafc9ynr0.png)
 
🔶 Provide Following Details and Install WordPress!
![WordPress › Installation - Google Chrome 05-09-2021 09_09_20 AM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jmlgpt9fr7r296q778mz.png)

🔶 After Login with the credentials and Login to WordPress!
![WordPress › Installation - Google Chrome 05-09-2021 09_09_31 AM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wuse2led2assp3rv0r49.png)

![WordPress › Installation - Google Chrome 05-09-2021 09_17_13 AM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awk644ey1wx5vi0dhveu.png)
##### Successfully done! We have Login in to WordPress and we can continue to write Blogs etc., All your Data will Be stored in RDS MySQL DB.
![68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f776174747061642d6d656469612d736572766963652f53746f7279496d6167652f69346776387341505f5f586746673d3d2d3931363135303430372e3136316636643238343363343039646134303138393](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yybi3w53tdcy9ct6uk38.gif)