How to host your website on EC2 instance & How you can upload and update the bundle using PSFTP?

AWS Services: AWS EC2 instance, AWS Route53.
Other: Putty, PSFTP.

Overview

We all know that nowadays the world is growing quite fast and also technologies are also increasing, even if the individuals are having a small business and wanted to grow fast they must be active in digital marketing, and for that website is a must.

Introduction & Working

The first step for growing your business is to have your website and from this blog, you will be able to learn how to host your website on AWS.

In this blog, we will discuss the following necessary steps to host a website on AWS:

  1. We will create an EC2 instance and will install an apache web server on it.

Implementation

Launch an EC2 Instance

  • Open an AWS Management console and under the ‘Services’ pane navigate to ‘EC2’ console.
  • Click on Running instances.
  • Here we can see that no instances are running so click on Launch Instances.
  • On this page, you have different options to choose from, choose the one which will satisfy your needs. I’m choosing t2.micro just for the tutorial purpose.
  • Here, configure your instance with the below-given details:
    Network: Default VPC.
    Subnet: Choose any one from the list.
    Auto-Assign Public Ip: Enable.
  • Click on ‘Next: Add Tags’ then again click on ‘Next: Configure Security Group’.
  • Click on ‘Launch’.
  • Click on ‘Launch Instances’ and again click on ‘Launch’.
  • Wait for Instance state from ‘Pending’ to ‘available’.

Convert your .PEM file to .PPK file

  • Download Putty and install it on your PC.
  • Click on Load and load the PEM file that you have recently downloaded and click on OK.
  • After uploading the file, click on ‘save private key’.
  • Give the name of that file and click on save.

Phew! We have converted.PEM file into.PPK file.

Taking SSH of our EC2 Instance

  • From the start-menu open PuTTY.
  • Now navigate to Connection > SSH > Auth and click on ‘Browse’. Choose the ppk file that you have downloaded from the previous step.
  • Click on Open and you will be able to take SSH to your EC2 instance and enter ‘ec2-user’ in login as.

(Note: Here hope that you will be able to take SSH to your EC2 instance, if not then kindly comment below I will get out of that problem. Currently not showing the troubleshooting else the blog length will be quite long.)

Updating EC2 instance & Installing and configuring Apache Web Server

  • Enter the below-given commands in the PuTTY SSH console:
    The -y option installs the updates without asking for confirmation.
sudo yum update -y
sudo yum install -y httpd24 php56 php56-mysqlnd
  • If you get the error message No package package-name available, then your instance was not launched with the Amazon Linux AMI. Verify the version of Amazon Linux with the following command.
cat /etc/system-release
  • Start the webserver with the command shown:
sudo service httpd start
  • Configure the webserver to start with each system boot using the chkconfig command.
sudo chkconfig httpd on

Note: To allow ec2-user to manage files in the default root directory for your Apache web server, modify the ownership and permissions of the /var/www directory. In this tutorial, you add a group named www to your EC2 instance. Then you give that group ownership of the /var/www directory and add write permissions for the group. Any members of that group can then add, delete, and modify files for the webserver.

  • Add the www group to your EC2 instance with the following command.
sudo groupadd www
  • Add the ec2-user user to the www group.
sudo usermod -a -G www ec2-user
  • Log out to refresh your permissions and include the new www group.
exit
  • Log back in again and verify that the www the group exists with the groups command.
groups ec2-user wheel www
  • Change the group ownership of the /var/www directory and its contents to the www group.
sudo chgrp -R www /var/www
  • Change the directory permissions of /var/www and its subdirectories to add group write permissions and set the group ID on subdirectories created in the future.
sudo chmod 2775 /var/www 
find /var/www -type d -exec sudo chmod 2775 {} +
  • Recursively change the permissions for files in the /var/www directory and its subdirectories to add group write permissions.
find /var/www -type f -exec sudo chmod 0664 {} +

Uploading files on your EC2 instance

  • We will see how to upload files and folder just by simple steps. I recommend if your bundle contains many folders and sub-folders then save that folder as .zip.
  • Open PSFTP on your local PC.
  • Use the command given below to transfer the file to your Linux Instance:
    (Note: If your folder is larger in size then wait for some time.)
mput filename.zip
This image is captured when the file was being uploaded.
  • After the file has been successfully uploaded then open your ongoing PuTTY connection and in that redirect to /var/www/html using command cd /var/www/html and after that by entering command ls you will be able to see the zip file that you have uploaded recently.
  • Unzip this file here by entering the command given below.
unzip filename.zip
  • Delete the zip file by entering the command:
rm filename.zip
  • Now, go back to your EC2 console and paste your public IP in your browser and hit enter, you will be able to see your website.

Mapping EC2 instance IP with Route53

  • Open AWSRoute53 console.
  • Navigate to Hosted Zones. Click on Create hosted zone.
  • So, finally, your dashboard will look like:
  • Copy all 4 your NS record and paste it into GoDaddy’s C-Panel.

Conclusion

Thus, with the reference of this blog, you will be able to host your own website on AWS EC2, upload our bundle on an EC2 instance, a map that instance with AWS Route53, and map route53 with the domain name on GoDaddy.

I hope, you like this blog, and if have any doubt then kindly comment below.

2x AWS Certified