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

Published: (March 12, 2026 at 07:37 AM EDT)
4 min read
Source: Dev.to

Source: Dev.to

Introduction

A real story from someone who figured it out with no job, no mentor, and no money.
I’m Prashik, a 25‑year‑old Computer Science graduate from Maharashtra. While most freshers were busy applying to jobs, I decided to deploy a real, production‑style server that anyone in the world could access.

Why AWS?

Every job description I read mentioned “AWS experience preferred.” I had completed the AWS Cloud Practitioner course, but concepts and hands‑on work are two completely different things. So I set out to build a live server on AWS EC2 and learn by doing.

Final Architecture

  • AWS EC2 instance – Ubuntu 22.04 LTS (free‑tier eligible)
  • Nginx – web server with custom server blocks
  • GitHub CI/CD pipeline – automatic deployment on each push
  • AWS Security Groups – firewall rules for SSH, HTTP, HTTPS
  • Publicly accessible website – reachable via the EC2 public IP

1. Launch an EC2 Instance

  1. Open the AWS Console → EC2Launch Instance.
  2. Choose Ubuntu Server 22.04 LTS (free tier).
  3. Select t2.micro (free tier).
  4. Create a new Key Pair, download the .pem file and keep it safe.
  5. Configure a Security Group (allow SSH port 22 and HTTP port 80 for now).
  6. Click Launch Instance.

2. Connect to Your Server

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

You are now inside your cloud server.

3. Install and Start Nginx

sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx

Visit http://your-ec2-public-ip in a browser – you should see the Nginx welcome page.

4. Configure a Server Block

Create a site configuration:

sudo nano /etc/nginx/sites-available/mywebsite
server {
    listen 80;
    server_name your-ec2-public-ip;

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

    location / {
        try_files $uri $uri/ =404;
    }
}

Enable the site and reload Nginx:

sudo ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

5. Prepare the Website Directory

sudo mkdir -p /var/www/mywebsite
sudo chown -R ubuntu:ubuntu /var/www/mywebsite

Copy your website files into /var/www/mywebsite. The site is now live.

6. Deploy via GitHub

On the EC2 server:

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

Create a simple deploy script:

nano /home/ubuntu/deploy.sh
#!/bin/bash
cd /var/www/mywebsite
git pull origin main
sudo systemctl reload nginx
echo "Deployed successfully!"

Make it executable:

chmod +x /home/ubuntu/deploy.sh

Run ./deploy.sh manually, or set up a GitHub Action to trigger it automatically.

7. Security Group Settings

TypeProtocolPortSource
SSHTCP22Your IP only
HTTPTCP800.0.0.0/0
HTTPSTCP4430.0.0.0/0

Important: Never leave port 22 open to 0.0.0.0/0. Restrict SSH access to your own IP.

8. Common Issues & Fixes

IssueCauseFix
Permission errors on /var/www/Wrong ownershipsudo chown -R www-data:www-data /var/www/mywebsite
sudo chmod -R 755 /var/www/mywebsite
Apache conflicts with NginxBoth services runningsudo systemctl stop apache2
sudo systemctl disable apache2
sudo systemctl restart nginx
SSH blockedSecurity group missing port 22 ruleAdd an inbound SSH rule for your IP
Nginx not reloading after config changeForgetting to test/reloadsudo nginx -t
sudo systemctl reload nginx

9. Technical Lessons

  • Security Groups are your first line of defense; configure them carefully.
  • Always run nginx -t before reloading to avoid breaking the server.
  • File permissions are critical on Linux servers.
  • Git‑based deployments are simple, powerful, and easily automated.

10. Life Lessons

  • You don’t need a job to build production‑level projects.
  • Every error message is a puzzle waiting to be solved.
  • The best way to learn cloud is to break things and fix them.
  • Building something real boosts confidence more than any certification.

11. Next Steps

After mastering a single instance, I moved on to a High Availability architecture with:

  • Application Load Balancer
  • Auto Scaling Groups across multiple Availability Zones
  • CloudWatch monitoring
  • Design for 99.9 % uptime

That story will be covered in a future article.

0 views
Back to Blog

Related posts

Read more »

AWS Cloud Praticttioner #01

Well, when I decided to focus my career in the area of DevOps, I searched for a roadmap. The roadmap highlighted the following topics: - Programming Languages:...