AWS Builder Center

πŸš€ How to Deploy a Website on Amazon EC2: A Beginner’s Guide

β€œHow can I make this website accessible to everyone on the internet?”

☁️ What is Amazon EC2?

Amazon EC2 (Elastic Compute Cloud) is an AWS service that pro

vides resizable virtual servers in the cloud.
Instead of purchasing a physical server, you can create an EC2 instance and use it as your own cloud-based computer.
You can use EC2 to host:
  • 🌐 Websites
  • πŸ–₯️ Web applications
  • πŸ”Œ APIs
  • 🐍 Python applications
  • 🟒 Node.js applications
  • πŸ—„οΈ Backend services
A simplified architecture looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Internet
β”‚
β–Ό
User
β”‚
β–Ό
Public IP Address
β”‚
β–Ό
EC2 Instance
β”‚
β–Ό
Web Server
β”‚
β–Ό
Your Website

πŸ› οΈ What Do We Need?

For this example, we will deploy a simple HTML/CSS website.
You will need:
  • An AWS account
  • An EC2 instance
  • A key pair for SSH access
  • A security group
  • A web server such as Apache
  • Your website files
The overall process is:
1
2
3
4
5
6
7
8
9
10
11
12
13
Create EC2
↓
Connect to EC2
↓
Install Web Server
↓
Upload Website
↓
Configure Security Group
↓
Open Public IP
↓
Website is Live πŸŽ‰

1️⃣ Create an EC2 Instance

First, open the AWS Management Console and navigate to EC2.
Choose:
Launch Instance
Give your instance a name such as:
1
My-First-Website
For the operating system, you can choose Ubuntu or another Linux-based AMI.
For a beginner project, a small instance type is generally sufficient.
You will also need to create or select a key pair.
The key pair is important because it allows you to securely connect to your EC2 instance.

2️⃣ Configure the Security Group

A Security Group acts like a virtual firewall for your EC2 instance.
For a basic website, you generally need to allow:
1
2
3
SSH β†’ Port 22
HTTP β†’ Port 80
HTTPS β†’ Port 443
For example:
TypePortPurpose
SSH22Connect to the server
HTTP80Website traffic
HTTPS443Secure website traffic
⚠️ Security tip: Avoid allowing SSH from 0.0.0.0/0 for production systems. Ideally, restrict SSH access to your own IP address or use a more secure access method.

3️⃣ Connect to Your EC2 Instance

After launching the instance, AWS provides connection instructions.
For Linux, you can connect using SSH.
The command generally looks like:
1
ssh -i "your-key.pem" ubuntu@YOUR_PUBLIC_IP
Here:
  • your-key.pem β†’ your private key
  • ubuntu β†’ the default user for an Ubuntu instance
  • YOUR_PUBLIC_IP β†’ your EC2 instance's public IP
Once connected, your terminal is now controlling your cloud server.
πŸŽ‰ You are inside your EC2 instance!

4️⃣ Update the Server

Before installing software, update the package list:
1
sudo apt update
You can also upgrade installed packages:
1
sudo apt upgrade
Keeping your server updated is an important security practice.

5️⃣ Install Apache Web Server

Now let's install Apache.
Run:
1
sudo apt install apache2 -y
After installation, check whether Apache is running:
1
sudo systemctl status apache2
If everything is working correctly, Apache should be active.

6️⃣ Test Your Server

Open your browser and enter:
1
http://YOUR_PUBLIC_IP
If Apache is working correctly, you should see the default Apache page.
This means your EC2 instance is successfully serving web content.

7️⃣ Upload Your Website

Apache usually serves website files from:
1
/var/www/html
The default page can be replaced with your own website.
For example, suppose your website contains:
1
2
3
4
index.html
style.css
script.js
images/
You can place these files inside:
1
/var/www/html
Your structure might look like:
1
2
3
4
5
6
/var/www/html
β”‚
β”œβ”€β”€ index.html
β”œβ”€β”€ style.css
β”œβ”€β”€ script.js
└── images/
Now Apache will serve your website from this directory.

8️⃣ Visit Your Website πŸŽ‰

Open:
1
http://YOUR_PUBLIC_IP
Your website should now be accessible through the internet.
Instead of:
1
localhost
you now have something similar to:
1
http://13.XXX.XXX.XXX
Your local website has officially been deployed to the cloud!

πŸ” What About HTTPS?

Using HTTP is fine for learning, but production websites should use HTTPS.
HTTPS encrypts communication between the user's browser and your server.
A common approach is:
1
2
3
4
5
6
7
8
9
Domain
↓
DNS
↓
EC2
↓
Apache
↓
HTTPS
You can use a domain name and configure an SSL/TLS certificate for your website.
AWS also provides services such as Elastic Load Balancing and AWS Certificate Manager that can be used in more production-oriented architectures.

πŸ’‘ Important EC2 Concepts to Understand

While deploying a website, you'll encounter several important AWS concepts.

Instance

An EC2 instance is your virtual server.

AMI

An Amazon Machine Image (AMI) provides the operating system and initial software configuration used to launch an instance.

Security Group

A virtual firewall controlling inbound and outbound traffic.

Public IP

The address that can be used to reach your server from the internet.

Key Pair

Used for secure authentication when connecting to your instance.

EBS

Amazon Elastic Block Store (EBS) provides persistent block storage for EC2 instances.

πŸ—οΈ Simple EC2 Website Architecture

The final architecture can be represented as:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
🌍 Internet
β”‚
β–Ό
Public IP
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Security Group β”‚
β”‚ 22 / 80 / 443 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ EC2 Instance β”‚
β”‚ Ubuntu β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
Apache Server
β”‚
β–Ό
Website Files
This is a simple architecture, but it introduces several fundamental cloud concepts.

⚠️ Don't Forget About AWS Costs

One important thing beginners should remember is:
Cloud resources can cost money.
Even if you are experimenting, always check the pricing and Free Tier eligibility applicable to your AWS account and region.
When you finish experimenting, stop or terminate resources that you no longer need.
Also check whether other resources, such as storage or public IPv4 addresses, are still being used.

πŸš€ What Can You Learn Next?

Once you understand basic EC2 deployment, you can make your architecture more production-ready.
You can explore:
1
2
3
4
5
6
7
8
9
10
11
12
13
EC2
↓
Elastic Load Balancer
↓
Auto Scaling
↓
RDS
↓
CloudWatch
↓
Route 53
↓
HTTPS
You can also learn how to deploy:
  • React applications
  • Node.js applications
  • Flask applications
  • Django applications
  • REST APIs
  • Docker containers

🎯 Final Thoughts

Deploying a website on EC2 is a great beginner project because it teaches you much more than simply putting a website online.
You learn about:
Servers β†’ Linux β†’ Networking β†’ Security β†’ Web Servers β†’ Cloud Deployment
The most important lesson is that cloud computing becomes much easier when you learn by building.
Start with a simple HTML website, deploy it on EC2, and then gradually add a domain, HTTPS, a database, monitoring, and automatic deployment.
Build locally β†’ Deploy to the cloud β†’ Monitor β†’ Improve β†’ Repeat. β˜οΈπŸš€
Happy building!
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article