π 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-WebsiteFor 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 443For example:
| Type | Port | Purpose |
|---|---|---|
| SSH | 22 | Connect to the server |
| HTTP | 80 | Website traffic |
| HTTPS | 443 | Secure 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_IPHere:
your-key.pemβ your private keyubuntuβ the default user for an Ubuntu instanceYOUR_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 updateYou can also upgrade installed packages:
1
sudo apt upgradeKeeping your server updated is an important security practice.
5οΈβ£ Install Apache Web Server
Now let's install Apache.
Run:
1
sudo apt install apache2 -yAfter installation, check whether Apache is running:
1
sudo systemctl status apache2If everything is working correctly, Apache should be active.
6οΈβ£ Test Your Server
Open your browser and enter:
1
http://YOUR_PUBLIC_IPIf 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/htmlThe 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/htmlYour 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_IPYour website should now be accessible through the internet.
Instead of:
1
localhostyou now have something similar to:
1
http://13.XXX.XXX.XXXYour 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
β
HTTPSYou 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 FilesThis 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
β
HTTPSYou 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!
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article