DEV Community

Cover image for How I Deployed a Production Server on AWS EC2 as a Fresher — Step by Step
Prashik besekar
Prashik besekar

Posted on

How I Deployed a Production Server on AWS EC2 as a Fresher — Step by Step

A real story from someone who figured it out with no job, no mentor, and no money


A Little Background

I'm Prashik. 25 years old. Computer Science graduate from Maharashtra.
No job yet. No salary. Just a laptop, an internet connection, and a burning desire to build something real.

While most freshers were busy applying to jobs and waiting, I decided to do something different — I wanted to actually deploy something live on the internet. Not localhost. Not a tutorial project. A real, production-style server that anyone in the world could access.

This is the story of how I did it — and everything I learned along the way.


Why AWS EC2?

Honestly? Because every job description I read mentioned AWS.

I kept seeing "AWS experience preferred" in job listings. I had done the AWS Cloud Practitioner course. I understood the concepts. But concepts and actually doing it are two completely different things.

So I decided — let me just do it. Let me set up a real server, deploy a real website, and figure out the problems as they come.

Spoiler: there were a LOT of problems. 😅


What I Built

Here's what the final setup looked like:

  • AWS EC2 instance — a virtual server running Ubuntu in the cloud
  • Nginx — a web server configured with custom server blocks
  • GitHub CI/CD pipeline — automatic deployment every time I push code
  • AWS Security Groups — firewall rules to control traffic
  • A live, publicly accessible website — visible to anyone with the link

Sounds simple. Getting there was not. 😄


Step 1 — Launch Your EC2 Instance

First things first — you need a server.

  1. Go to AWS Console → EC2 → Launch Instance
  2. Choose Ubuntu Server 22.04 LTS (free tier eligible)
  3. Select t2.micro — this is free tier, costs you nothing
  4. Create a new Key Pair — download the .pem file and keep it safe. If you lose this, you lose access to your server forever.
  5. Configure Security Group — for now allow SSH (port 22) and HTTP (port 80)
  6. Launch the instance

Your server is now running somewhere in Amazon's data center. Pretty cool right? 🚀


Step 2 — Connect to Your Server

On your local machine, open terminal and run:

chmod 400 your-key-pair.pem
ssh -i "your-key-pair.pem" ubuntu@your-ec2-public-ip
Enter fullscreen mode Exit fullscreen mode

You're now INSIDE your cloud server. This felt like magic to me the first time. 😄


Step 3 — Install Nginx

Nginx is the web server that will serve your website to the world.

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 public IP in a browser — you should see the Nginx welcome page.

Your server is live on the internet. 🎉


Step 4 — Configure Nginx Server Blocks

Server blocks let you host multiple websites on one server (like virtual hosts in Apache).

sudo nano /etc/nginx/sites-available/mywebsite
Enter fullscreen mode Exit fullscreen mode

Add this configuration:

server {
    listen 80;
    server_name your-ec2-public-ip;

    root /var/www/mywebsite;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
Enter fullscreen mode Exit fullscreen mode

Then enable it:

sudo ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

Step 5 — Deploy Your Website Files

Create your website directory and add your files:

sudo mkdir -p /var/www/mywebsite
sudo chown -R ubuntu:ubuntu /var/www/mywebsite
Enter fullscreen mode Exit fullscreen mode

Now copy your website files here. Your site is live!


Step 6 — Set Up CI/CD with GitHub

This was my favourite part. Every time I push code to GitHub — it automatically deploys to the server. No manual copying files.

On your EC2 server:

cd /var/www/mywebsite
git init
git remote add origin https://github.com/yourusername/your-repo.git
git pull origin main
Enter fullscreen mode Exit fullscreen mode

Then create a simple deploy script:

nano /home/ubuntu/deploy.sh
Enter fullscreen mode Exit fullscreen mode
#!/bin/bash
cd /var/www/mywebsite
git pull origin main
sudo systemctl reload nginx
echo "Deployed successfully!"
Enter fullscreen mode Exit fullscreen mode
chmod +x /home/ubuntu/deploy.sh
Enter fullscreen mode Exit fullscreen mode

Now whenever you want to deploy — just SSH in and run ./deploy.sh. Or set up a GitHub Action to do it automatically!


Step 7 — Configure Security Groups Properly

This is where I made mistakes and learned hard lessons.

In AWS Console → EC2 → Security Groups, make sure you have:

Type Protocol Port Source
SSH TCP 22 Your IP only
HTTP TCP 80 0.0.0.0/0
HTTPS TCP 443 0.0.0.0/0

Important: Never leave port 22 open to 0.0.0.0/0 (everyone). Only allow your own IP for SSH. I learned this the hard way when I saw unknown login attempts in my logs. 😅


Problems I Hit (And How I Solved Them)

Problem 1 — 403 Forbidden Error

Cause: Wrong file permissions on /var/www/
Fix:

sudo chown -R www-data:www-data /var/www/mywebsite
sudo chmod -R 755 /var/www/mywebsite
Enter fullscreen mode Exit fullscreen mode

Problem 2 — Port 80 Already in Use

Cause: Apache was running alongside Nginx
Fix:

sudo systemctl stop apache2
sudo systemctl disable apache2
sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Problem 3 — Can't Connect via SSH

Cause: Security group didn't have port 22 open
Fix: Go to AWS Console → Security Groups → Edit Inbound Rules → Add SSH rule

Problem 4 — Changes Not Reflecting

Cause: Nginx wasn't reloaded after config changes
Fix:

sudo nginx -t        # Always test config first
sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

What I Learned

Technical lessons:

  • AWS Security Groups are your first line of defense — configure them carefully
  • Always run nginx -t before reloading — it saves you from breaking your server
  • File permissions matter more than you think in Linux
  • Git-based deployments are simple but powerful

Life lessons:

  • You don't need a job to build production-level things
  • Every error message is just a puzzle waiting to be solved
  • The best way to learn cloud is to actually break things and fix them
  • Building something real gives you more confidence than any certification

What's Next

After this I built a High Availability Architecture on AWS with:

  • Application Load Balancer
  • Auto Scaling Groups
  • Multiple Availability Zones
  • CloudWatch monitoring
  • 99.9% uptime design

But that's a story for another article. 😄


Final Thoughts

If you're a fresher reading this feeling stuck — just start building.

You don't need a job to gain experience. You don't need money to use AWS free tier. You don't need a mentor to figure things out.

You just need to start, make mistakes, fix them, and keep going.

That's exactly what I did. And I'm still going. 💪


If this helped you, follow me for more real stories about backend development, AWS, and the journey of building things from scratch.

Connect with me on LinkedIn: linkedin.com/in/prashik-besekar
GitHub: github.com/prashikBesekar

Top comments (0)