DEV Community

Yash Sonawane
Yash Sonawane

Posted on

Deploy a Full Website on EC2 with Apache/Nginx (Using AWS Free Tier) ๐Ÿš€

โ€œCan I host a full-blown website on AWS... for free?โ€

YES, you can โ€” and today Iโ€™ll show you exactly how to do it using EC2, Apache or Nginx, and zero jargon. Letโ€™s go from idea to live website in under 30 minutes. ๐Ÿ’ก๐Ÿ’ป


๐Ÿง  Why Use EC2 to Host a Website?

Think of EC2 like renting a house (server) where you can host anything โ€” your website, backend, or portfolio. You get full control, root access, and scalability.

Real-world analogy: EC2 is like leasing your own plot of land (server) in the cloud, and Apache/Nginx is the building you construct on top to serve guests (visitors).

And with the AWS Free Tier, your first 750 hours/month (t2.micro instance) are completely free for 12 months. ๐ŸŽ‰


๐Ÿงฐ What Youโ€™ll Need

  • An AWS account (Free Tier enabled)
  • A simple website (HTML/CSS/JS files)
  • Basic terminal skills (copy-paste works too!)

๐Ÿ— Step-by-Step: Launch Your EC2 Instance

1. Go to the EC2 Dashboard

2. Launch a New Instance

  • Name: my-website-server
  • AMI: Amazon Linux 2 (or Ubuntu)
  • Instance Type: t2.micro (Free Tier)
  • Key Pair: Create new one, download .pem file
  • Security Group: Allow ports 22 (SSH), 80 (HTTP), and optionally 443 (HTTPS)

3. Launch and Connect

Once itโ€™s running, click โ€œConnectโ€ and follow the instructions for SSH:

chmod 400 my-key.pem
ssh -i my-key.pem ec2-user@<your-ec2-ip>
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”ง Install Apache or Nginx

Choose one:

Option A: Install Apache

sudo yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
Enter fullscreen mode Exit fullscreen mode

Visit http://<your-ec2-ip> โ€” youโ€™ll see the Apache test page ๐ŸŽ‰

Option B: Install Nginx (Ubuntu example)

sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
Enter fullscreen mode Exit fullscreen mode

Now go to your EC2 IP in the browser โ€” Nginx is live!


๐Ÿ“ Upload and Host Your Website

1. Replace Default Files

cd /var/www/html  # Apache
cd /var/www/      # Nginx (usually /var/www/html or /usr/share/nginx/html)
Enter fullscreen mode Exit fullscreen mode

2. Create an index.html

echo "<h1>My EC2 Website is Live! ๐Ÿš€</h1>" | sudo tee index.html
Enter fullscreen mode Exit fullscreen mode

3. Or Upload Your Site Files

Use scp (from your local machine):

scp -i my-key.pem * ec2-user@<your-ec2-ip>:/var/www/html/
Enter fullscreen mode Exit fullscreen mode

๐ŸŒ Optional: Add a Custom Domain (Bonus)

  • Buy a domain from GoDaddy, Namecheap, etc.
  • Point your domainโ€™s A record to your EC2 public IP
  • BOOM โ€” your website is live with your domain ๐Ÿš€

Want HTTPS? You can install a free SSL using Letโ€™s Encrypt + Certbot (ask in comments and Iโ€™ll write a full guide!)


๐Ÿง  Quick Recap

Step What You Did
1๏ธโƒฃ Launched an EC2 instance on Free Tier
2๏ธโƒฃ Installed Apache or Nginx to serve content
3๏ธโƒฃ Uploaded website files to /var/www/html/
4๏ธโƒฃ (Optional) Mapped a domain to your site

You now have a fully deployed, production-ready static site running in the cloud ๐Ÿ’ช


๐Ÿ™Œ Final Thoughts

Thereโ€™s something empowering about deploying your own website using real servers.
Youโ€™re not just learning AWSโ€”youโ€™re building confidence as a developer.

Want to go further? Add SSL, host a blog, or automate deployments with CI/CD.


๐Ÿ’ฌ Your Turn!

Did this guide help you go live on EC2? What did you deploy โ€” a portfolio, a side project, or a meme site? ๐Ÿ˜„

๐Ÿ‘‡ Drop a comment, smash โค๏ธ if this saved you hours, and share with someone ready to ditch shared hosting forever!

Letโ€™s build cool things in the cloud โ€” together. ๐Ÿงก

Top comments (0)