AWS

How to Host a Website on AWS EC2

Hosting a website on any platform can become a bit complicated, as there are so many options to choose from. AWS provides an easy and simple process of hosting a website using an EC2 Virtual machine. You can create your virtual machine from anywhere in the globe and host your website using an EC2 virtual machine and this post will teach you how to host a website on AWS using EC2.

Let’s start with the process of how to host a website on an AWS EC2 instance.

Host a Website on AWS EC2

To host a website on an AWS EC2 instance, create an EC2 virtual machine from the Amazon EC2 dashboard. Then click on the “Connect” button to connect to the virtual machine:

Select the “SSH client” section and copy the command for connection from the “Example” command.

Paste the copied command on either the command prompt or PowerShell. And change the key pair file location according to your PC. After entering the command simply press enter to connect to your virtual machine using the SSH client:

Once you are connected to your virtual machine, write the following command to install “HTTP Server”:

yum install -y httpd

After the command, hit enter to execute the command and it will install the HTTP Server.

After the installation, to check the status of the HTTP Server, type the following command:

systemctl status httpd

The HTTP server is “inactive” for now:

To make the server active, you need to type the following command:

systemctl enable httpd

systemctl start httpd

Now your HTTP server is in an “active” state and ready to host a website:

Now you have to create a directory, in which you can load your website files in that directory so we have created a directory with the name “temp”. To create a directory and access the directory, simply write the following commands:

mkdir temp

cd temp

After the directory is created and accessed, let us store the website files in the directory for that, simply type the following command:

wget <link of the website>

The complete command we used here is as following:

wget https://www.htmlwentemplates.co.uk/wp-content/uploads/2020/85/Elements.zip

Using this command your website files are loaded into the directory:

To check if the file has been loaded or not type the following command:

ls -lrt

You can see the name of the file is in the “zip” format:

To unzip the file simply type the following command:

unzip <File name with extension>

The command we used here is mentioned below:

unzip Elements.zip

Press enter after typing the command and it will start unzipping the file:

To check if the file is unzipped or not type the following command:

ls -lrt

You can see that file has been unzipped.

To convert this HTTP server into a Web server you need to convert these files into a separate directory and it can be done by following commands:

mv * /var/www/html

cd /var/www/html

Your website files have been moved to a separate directory, to check that type the following command:

ls -lrt

Here you can see all the files have been moved to the directory from the screenshot below:

You are done with all the configurations for hosting a website. You can simply copy the “Public Address” of your EC2 instance and paste it on any web browser:

You can see that your website has been hosted on AWS using an EC2 instance:

You have successfully hosted a website on AWS using an EC2 instance.

Conclusion

To host a website on AWS using an EC2 instance you need to create an EC2 virtual machine and make a connection with it. After that simply type a series of commands to install a web server and upload your website files. These commands will make the pathway to host a website on AWS. After the configurations using commands simply copy the “Public Address” of your EC2 virtual machine and paste it into any web browser. Your website is available for public use. This post has taught you how to host a website on AWS EC2.

About the author

Abdul Mannan

I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor's degree in computer science.