Create an EC2 instance config with apache web server and launch wordpress site using AWS (RDS&EC2)

So, I was presented to AWS (Amazon Web Services) in one of our graduation courses (chandigarh university). Basically, it is a set of cloud services like computing, storage, internet of things, artificial intelligence, etc. I’ve made a quick research about these services and realized it is possible to combine two of them to create and host a Wordpress site, one is called EC2 (Elastic Compute Cloud) which is a virtual server, the other is called RDS (Relational Database Service) which is a database manager.

AWS offers a starting experience package called Free Tier, where they give you access to use many services for free within a year (see their site here), but we are considering the creation of the website using their default URL, so if you’d like to buy a domain AWS offers this service as well on Route 53 for about C$12 depending on which name you want and around C$0.54 per month (maintenance). The price rises considerably after the one year trial (around C$20 per month), but this is logical because we’re paying for a virtual server and a database management services, and a Wordpress site is only a small portion of the real potential for these two services (see pricing of EC2) (see pricing of RDS).

In the next chapters, I’ll explain how to create these services and host a Wordpress site. So let’s go to the solution!

1. AWS Free Tier & Creating an Account

When we open the AWS landing page (free tier session), the company highlight its main services eligible for the year free experience, and we can already see the two services we’re going to use for the tutorial. Both services, EC2 and RDS, have 750 hours per month free access each (within a year), that means we can use one EC2 instance and one RDS instance free (24h x 31days = 744h)

The first thing we need to do is create an AWS account, so go to AWS website and follow their steps.

2. Hands On

2.1. Security Groups

In AWS console main page, you can see a service search field, type “EC2” and click on the first search result

On the left-side menu bar, click on the security groups option.

We’ll create two groups, server-tier and db-tier, the first one will be responsible to allow only you to access the server through SSH, and everyone to access the website through HTTP, the second one will be responsible to allow only you and the server to access the database.

Create a new group:

  • On the name field I’m typing “server-tier”
  • On the description field I’m typing “traffic into and out of servers”
  • On the VPC I’m leaving it to default
  • Add a new rule to the group
  • Choose “HTTP” for the type
  • Leave the protocol and port range to defaults
  • Choose “Anywhere” for the source
  • Give it a description
  • Add another rule to the group
  • Choose “SSH” for the type
  • Leave the protocol and port range to defaults
  • Choose “My IP” for the source
  • Give it a description
  • Click on Create

Copy the Group ID just created, you’ll use it for the second group.

Create another group:

  • On the name field I’m typing “db-tier”
  • On the description field I’m typing “traffic into database”
  • On the VPC I’m leaving it to default
  • Add a new rule to the group
  • Choose “MYSQL/Aurora” for the type
  • Leave the protocol and port range to defaults
  • Choose “Custom” for the source and paste the Group ID created for the server-tier
  • Give it a description
  • Add another rule to the group
  • Choose “MYSQL/Aurora” for the type
  • Leave the protocol and port range to defaults
  • Choose “My IP” for the source
  • Give it a description
  • Click on Create

2.2. Creating RDS Instance

Back to the AWS console main page, type “RDS” and click on the first search result.

On the RDS console main page, click on Get Started Now to create a new instance. Check the option Only enable options eligible for RDS Free Usage Tier to secure the usage of the free tier.

Choose the option MySQL and click “Next”.

In the Step 1, at the Settings section, give a name for the instance and a username and password. The rest of the options we can leave as it is.

n the Step 2, select yes for the Public accessibility option, then choose db-tier for the VPC security groups option and leave only this security group (delete any other associated).

Give a name for your first database of this instance, and leave the rest of the options as it is.

Click on Launch DB instance to initiace the creation process. You can follow the status by clicking Instances on the left-side menu bar.

2.2.1. Checking Connection

We can try connecting to the instance as soon as it’s finished the creation process. I’ll use MySQL Workbench, just install from their website.

For the hostname, use the endpoint created with the RDS instance.

And you can check your databases created by fetching the command show databases.

2.3. Creating EC2 Instance

Back to the AWS console main page, type “EC2” and click on the first search result.

Click on Launch Instance to start the creation process.

In the Step 1, check the Free tier only option. Let’s choose the first option here (Amazon Linux AMI 2017.09.0 (HVM), SSD Volume Type).

In the Step 2, check the Free tier eligible option and click Next: Configure Instance Details.

For the Steps 3, 4, and 5, leave the options as they are and click Next.

In the Step 6, select the previously created server-tier security group. Click on Review and Launch.

Review your options and click on Launch. A pop-up window is shown asking you to use or create a key pair for secure connection, so create a new key pair and download it, and click on Launch Instances.

2.3.1. Connecting Via SSH

By finishing the EC2 instance creation process, click on Connect to get the guide for SSH connection.

2.3.2. Checking Connection To RDS

In the EC2 instance, update the modules using the command below.

Install the MySQL client.

Connect to the RDS instance using the endpoint created and the username and password.

Type a command to test the connection.

Type exit to close the connection.

2.4. Creating And Hosting Wordpress Site

To create and host a Wordpress site, we need basically three “things”: an Apache server, PHP, and MySQL. The MySQL database we already have from the RDS instance create in the previous chapters, let’s install Apache and PHP.

In the EC2 instance, type the following command to install Apache, PHP, and the communication driver to PHP/MySQL.

Start the Apache service and test it in a web browser (using the EC2 endpoint).

Now, stop the Apache service.

Add this user (EC2-USER) to apache group.

Log out of EC2 and log in again to make effect.

Change the group ownership of /var/www and its contents to apache group.

Add to the group write permissions and set group ID on future subdirectories and files.

Download Wordpress from its website.

Unzip the file.

Create the wp-config.php file from sample provided and edit it.

Edit the file according to the RDS instance created. Also, generate the authentication keys from the website specified in the comments and paste in the file.

Go outsite the wordpress directory and copy all the content of the wordpress directory to /var/www/html/.

To allow permalinks feature change the file in /etc/httpd/conf/httpd.conf.

Inside the tag <Directory "/var/www/html"> change the AllowOverride to All.

Start the Apache service.

To start the apache service every time you initiate EC2.

Finally, check your website (on EC2 endpoint)

nd it’s working! YEAHHH!

3. Conclusion

AWS offers some good services for a year for free, and if you’d like just to create and host a Wordpress site you can create yours for a very low cost monthly (considering you want to use your domain). After the free one year experience, the price will rise consistently and you might want to evaluate other options like Hostgator or GoDaddy. Another possible option is to install MySQL Server inside the EC2 instance, so you don’t need the RDS for this case, and the final cost would drop considerably.

4. Resources

THANK YOU …..

read and share …

self learner ! Engineer ! dedication to learn new skills