How to host a website on AWS EC2 instance | Hosting website in AWS | AWS Tutorial

Today we are going to host a website on the AWS cloud free of cost. Following the steps, we are going to follow in this tutorial

 

1] Buy a domain name from here.

This will be free of cost and it will help our website to recognize easily. At the end we are going to change the type A record in the DNS system.

2] Creating an EC2 instance and installing apache2.

This will act as a server.

After doing this our server will be ready. Now we have to move our code to our EC2 instance for that we need to upload it to AWS S3 and make it publically accessible.

3] Creating a public bucket and uploading our files in it

After creating the bucket and uploading our folder into it we need to do the following 2 things

1. keep OFF the block all public access feature

2. Change the bucket policy as per the following

After this, our bucket will be public and with the help of the link, we will be able to download it.

 

Now it’s time to upload our code to the server.

 

4] Uploading code to the server

 

Make sure you logged in to your EC2 instance as the root user. Now execute the following commands

 

cd /var/www/html

wget *bucket-url* 

unzip *folder-name*

mv folder-name/* .

 

Now our server is ready and one last thing we need to do is to connect it with the domain name that we purchased on freenom.

 

5] Connecting domain name with the server

Points to remember.

AWS changes the IP address of the EC2 every time we turn on and off the EC2 instance. So we need to have a permanent IP address that will not be changed even after turning off the EC2. We can achieve this using AWS Elastic-IP.

 

Another 2 sub-steps needs to followed in order to solve above proble

Step 1 – Set up Elastic IP.(Static IP for our EC2)

Step 2 – Update your domain’s DNS records to point to your elastic IP

 

After doing all our website will be up and running.

 

 

 

Leave a Comment