How to Set Up AWS EC2 Ubuntu Server with Apache2 Using Free Tier
Amazon Web Services (AWS) provides a powerful EC2 Free Tier that allows developers and beginners to deploy servers at zero cost. In this guide, you’ll learn how to set up an AWS EC2 Ubuntu server with Apache2 step by step.
What Is AWS EC2?
Amazon EC2 (Elastic Compute Cloud) is a scalable cloud service that allows you to run virtual servers called instances. These instances can host websites, APIs, and applications.
AWS Free Tier Eligibility
- 750 hours per month of t2.micro or t3.micro instance
- Ubuntu Server supported
- Free for 12 months from account creation
Prerequisites
- An AWS account
- Basic Linux knowledge
- SSH client (Terminal or PuTTY)
- Internet connection
Step 1: Create an AWS Account
Visit https://aws.amazon.com and sign up using your email, phone number, and credit card. AWS will not charge you if you stay within Free Tier limits.
Step 2: Launch an EC2 Ubuntu Instance
Select AMI
Choose Ubuntu Server 22.04 LTS (Free Tier Eligible).
Select Instance Type
Choose t2.micro or t3.micro.
Step 3: Create and Download Key Pair
- Create a new key pair
- Download the .pem file
- Store it securely
Step 4: Configure Security Group
- SSH – Port 22 (Your IP)
- HTTP – Port 80 (Anywhere)
- HTTPS – Port 443 (Anywhere)
Step 5: Connect to EC2 Ubuntu via SSH
For Mac / Linux
chmod 400 your-key.pem ssh -i your-key.pem ubuntu@your-ec2-public-ip
For Windows (PuTTY)
- Convert .pem to .ppk using PuTTYgen
- Username: ubuntu
- Host: EC2 Public IP
Step 6: Update Ubuntu Server
sudo apt update sudo apt upgrade -y
Step 7: Install Apache2 Web Server
sudo apt install apache2 -y sudo systemctl start apache2 sudo systemctl enable apache2
Step 8: Configure Firewall for Apache
sudo ufw allow 'Apache Full' sudo ufw reload
Step 9: Verify Apache2 Installation
Open your browser and enter your EC2 public IP address. You should see the Apache2 Ubuntu Default Page.
Step 10: Apache Document Root Location
Your website files are located at:
/var/www/htmlYou can upload your HTML or PHP files here.
Best Practices for AWS Free Tier
- Stop EC2 instance when not in use
- Monitor usage in AWS Billing Dashboard
- Use IAM users instead of root account
- Delete unused volumes and IPs
Common Issues and Fixes
- Permission denied (publickey) – Check key permissions
- Connection timeout – Verify security group rules
- Apache page not loading – Check port 80 access
Want to learn how to install PHP 8.3 and MySQL? Click here for a complete step-by-step guide.