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)