How I Deployed a Production Server on AWS EC2 as a Fresher — Step by Step
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
- Open the AWS Console → EC2 → Launch Instance.
- Choose Ubuntu Server 22.04 LTS (free tier).
- Select t2.micro (free tier).
- Create a new Key Pair, download the
.pemfile and keep it safe. - Configure a Security Group (allow SSH port 22 and HTTP port 80 for now).
- Click Launch Instance.
2. Connect to Your Server
chmod 400 your-key-pair.pem
ssh -i "your-key-pair.pem" ubuntu@your-ec2-public-ipYou 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 nginxVisit 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/mywebsiteserver {
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 nginx5. Prepare the Website Directory
sudo mkdir -p /var/www/mywebsite
sudo chown -R ubuntu:ubuntu /var/www/mywebsiteCopy 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 mainCreate 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.shRun ./deploy.sh manually, or set up a GitHub Action to trigger it automatically.
7. Security Group Settings
| 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. Restrict SSH access to your own IP.
8. Common Issues & Fixes
| Issue | Cause | Fix |
|---|---|---|
Permission errors on /var/www/ | Wrong ownership | sudo chown -R www-data:www-data /var/www/mywebsitesudo chmod -R 755 /var/www/mywebsite |
| Apache conflicts with Nginx | Both services running | sudo systemctl stop apache2sudo systemctl disable apache2sudo systemctl restart nginx |
| SSH blocked | Security group missing port 22 rule | Add an inbound SSH rule for your IP |
| Nginx not reloading after config change | Forgetting to test/reload | sudo nginx -tsudo systemctl reload nginx |
9. Technical Lessons
- Security Groups are your first line of defense; configure them carefully.
- Always run
nginx -tbefore 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.