Host Dynamic Website Using AWS EC2 Instance

Lakshmi Last Updated : 16 May, 2022
7 min read

This article was published as a part of the Data Science Blogathon.

Introduction on EC2

In this article, we will learn how to host a dynamic website using an EC2 instance. Many will create a dynamic website and will confuse about where to host it and how to host it. In this article, I will help you guys for hosting them.

Amazon Elastic Compute Cloud is a web-based service that allows us to run our applications in the Amazon Web Service (AWS).

We will learn some basics of EC2 before going into the hosting part.

What is EC2?

EC2 refers to Elastic Computing Cloud. It is an IaaS that is Infrastructure as a service. EC2 is one of the services provided by Amazon. It is one of the most useful services. Here, using Amazon EC2 you can launch as many as virtual servers you want. It offers secure and high scalable compute capacity. Here there is the possibility of scaling up and scaling down according to the requirement you have. This is also an advantage of Amazon EC2. Virtual machines and EC2 instances are almost similar and also they work similarly. One of the main advantages of using EC2 is Elastic Load Balancing. Here, it automatically distributes the traffic across multiple Amazon EC2 instances.

Amazon EC2 uses the AWS Management Console, the AWS Command Line Interface (CLI), or AWS Software Developer Kits (SDKs) for scaling according to changes needed for the end-user, and finally, it will be simple to deploy virtual servers and also to maintain storage and also makes it simple to deploy virtual servers and also to maintain storage.

Features of Amazon EC2

The features that are provided by the Amazon EC2 are,

  • It provides instances
  • It has multiple templates with software configurations. These are known as Amazon Machine Images( AMIs).
  • Instance types include CPU configurations, storage, memory, and also the networking capacity of the instance.
  • Key pairs provide secure login information.
  • Temporary data such as data that was deleted is known as instance store volumes
  • Multiple physical locations are available across the globe
  • For dynamic cloud computing, the static IPv4 addresses are known as Elastic IP Addresses and many more.

Instance: Instance is a virtual server that is launched using the Amazon EC2 service.

We are hosting this instance using a free tier, yet let’s see the pricing of an EC2 instance.

It works on a pay as you go and so you have to pay for only what you have used. This instance runs at a cost of $0.192 per hour. For one year it will cost $530 upfront and $44.15 per month and the total is about $1,060.

Types of Instances

We can choose different Amazon EC2 instances based on the requirements for our application and also the workload.

1. General Instances: For the services that are related to web servers, gaming development applications, or big applications like enterprise-level applications General instances are the best choice.

2. Memory Instances: To process larger datasets with a fast speed, these memory instances are used.

3. Compute Instances: By the name itself, it suggests that they are used during the workloads that can benefit professors with high computing power.

4. Accelerated Computing: This type of instance provides computing capacity for very high performance. These workloads are supported by external hardware known as GPU(Graphics Processing Unit).

5. Storage Instances: When we deploy applications that require high storage requirements, we used storage instances.

Now let’s see the benefits of Amazon EC2.

Benefits of EC2

1. Scalability: Amazon EC2 provides high scalability so when needed we can add instances and we can adjust them according to the demand.

2. Security: EC2 has several built-in security features which make you feel comfortable using EC2.

3. Flexibility: it provides you to choose multiple types of instances, various software packages, os, and instance storage.

4. Cost-effective: It is very cost-effective. We have to pay only for what we have used.

5. Computing Capacity: It provides a secure and resizable compute capacity.

6. Reliable: These services are very reliable. Here we can do replacement of instances very easily and rapidly.

7. Servers in Multiple Regions: These services are available in multiple regions across the globe. So we can prefer locations near to us.

Hope you have gained some knowledge of EC2. Now let’s move on to the hosting part.

Hosting Website

For hosting first, you have to be ready with all your files and make them in one folder.

Next Log in to AWS.

Select Root User and enter the mail with which you have created the AWS account.

AWS

Next enter the Captcha and then enter the password finally to successfully log in.

After that select the region near to your place and also the region where the EC2 service is available. And then search for EC2 and open it.

Click on instances to launch a new instance. Remember that we have to launch a new instance which is a virtual server to host our website.

EC2 Instance

Now there will be steps. those are:

1. Choose AMI

2. Choose Instance Type

3. Configure Instance

4. Add Storage

5. Add Tags

6. Configure Security Group

7. Review

Let’s come one by one.

The first one is choosing Amazon Machine Image (AMI).

Before launching an instance we have to select it. Amazon Machine Image (AMI) provides all the information that is required for you to launch an instance. Using a single AMI you can launch multiple instances. It is useful when you need to launch multiple instances of the same configuration.

Amazon Machine Image (AMI) is like a template that contains software configuration. Examples include an operating system, application servers, and like applications.

Here I have selected Microsoft Windows Server 2019 Base.

We can select whatever we want.

Microsoft Windows Server (Step 1)

Next, choose an instance type.

Here only one is eligible for the Free tier and so it will be selected automatically. So directly you can click Next.

Microsoft Windows Server (Step 2)

Next, Configure the instance.

As we are going to launch only one instance no changes were needed here. Just click on Next.

Microsoft Windows Server (Step 3)

Next is adding storage.

Here also no need for any changes click on Next.

And 5th step is adding tags.

Here too no need for any changes click Next.

Next, Configure Security Group.

Here for security purposes, we have to add two RDPs. They are HTTP and HTTPS.

Microsoft Windows Server (Step 6)

Finally, click on Review and Launch.

Check everything if it is ok and then Launch.

Now we have to select key pair. Create one new key pair with any name and then download Keypair.

And click on Launch Instances.

Then go to view instances and wait till the status check turns to 2/2 checks passed.

instances check 1

Now check the box and click on connect.

And then click on RDP client. Now if you don’t have a remote desktop on your local system then click on download remote desktop.

Then it will download the remote desktop.

At the bottom, you will find Get Password. Click on it. Browse for the keypair file which you have downloaded earlier and click on Decrypt Password. Copy Public DNS.

Now go to the search bar on your local desktop and search for Remote Desktop connection. And for computers paste the public DNS and then connect.

Enter username and Password by copying from RDP Client and then press OK.

Open internet explorer and download the Xampp server from apache Friends on your Remote desktop. 

Then Xampp control panel will open and click start for Apache and then click start for Mysql and then click on Admin for Mysql.

And Now open File Explorer on your Remote Desktop. In C drive you will find the Xampp folder and in that open the htdocs folder and in that paste the folder in which all your files related to the website were saved. Rename its dashboard. Before that rename the folder which is named dashboard to some different name.

Now go to that Xampp server.

Click on new on the left panel and then go to import and browse the SQL file in the dashboard folder and then click on Go.

Your website has been hosted successfully now. To view it you can search Public DNS on any browser and on any desktop either its local or Remote desktop.

Conclusion on EC2

This is how you can host your dynamic website using the Amazon EC2 instance. Using this EC2 instance we can host our dynamic website very simple than we expected. If you are just practising how to host the website with the Free tier account, then don’t forget to terminate the instance once you are done. Else Amazon will charge you for what you have used. Overall in this article, we have understood

–> First of all we have learned to host a dynamic website.

–> For that, we have used a virtual remote desktop and hosted it in the Xampp server.

–> We have seen what is EC2, what are the types of instances and also the benefits of EC2.

Hope you guys found it useful.

Connect with me on LinkedIn

The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.

Responses From Readers

Clear

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details