Deploying a Static Website on AWS Ubuntu EC2 with Apache2
Deploying a Static Website on AWS Ubuntu EC2 with Apache2
Introduction
This guide provides a step-by-step process to deploy a static website on an AWS EC2 instance running Ubuntu with Apache2. It covers instance setup, Apache installation, file deployment, and basic security configurations.
Prerequisites
An AWS account
Basic knowledge of Linux commands
An existing static website (HTML, CSS, JS files)
Step 1: Launch an Ubuntu EC2 Instance
Log in to AWS Management Console.
Navigate to EC2 Dashboard > Instances.
Click Launch Instance.
Select Ubuntu as the AMI.
Choose an instance type (e.g., t2.micro for free tier).
Configure security group:
Allow SSH (port 22) for your IP.
Allow HTTP (port 80) and HTTPS (port 443) for anywhere.
Launch the instance and download the key pair (.pem file).
Step 2: Connect to the EC2 Instance
Open a terminal and navigate to the directory containing the
.pemfile.Run the following command to connect:
ssh -i your-key.pem ubuntu@your-ec2-public-ip
Step 3: Update System Packages
sudo apt update && sudo apt upgrade -yStep 4: Install Apache2
sudo apt install apache2 -yVerify Apache is running:
sudo systemctl status apache2Enable Apache to start on boot:
sudo systemctl enable apache2Step 5: Deploy Static Website Files
Navigate to the Apache web root directory:
cd /var/www/htmlRemove the default Apache page:
sudo rm index.htmlUpload your website files (via SCP or manual transfer):
sudo cp -r /your/local/directory/* /var/www/html/Set proper permissions:
sudo chmod -R 755 /var/www/html sudo chown -R www-data:www-data /var/www/html
Step 6: Configure Firewall and Security Groups
Enable UFW and Allow Apache:
sudo ufw allow 'Apache'
sudo ufw enableVerify Firewall Status:
sudo ufw statusEnsure AWS Security Groups Allow HTTP/HTTPS
Go to EC2 Dashboard > Security Groups.
Edit Inbound Rules:
Allow HTTP (port 80) from anywhere.
Allow HTTPS (port 443) from anywhere.
Step 7: Access the Website
Open a browser and enter:
http://your-ec2-public-ipYour static website should be live!
Troubleshooting
Permission Denied Issues: Use
sudobefore commands.Apache Not Running: Restart with
sudo systemctl restart apache2.Site Not Loading: Check security group rules and firewall settings.
Next Steps
Secure your site with an SSL certificate (Let’s Encrypt).
Use a domain name with Route 53.
Deploy a dynamic website with databases.
Conclusion
By following this guide, you have successfully deployed a static website on an AWS Ubuntu EC2 instance using Apache2. This is a great foundation for future projects like dynamic applications or cloud-based solutions.
Connect me on :
LinkedIn : www.linkedin.com/in/thisararupasinghe
YouTube : https://youtube.com/@thisararupsinghe?si=ts0K6VDwdaCqe6P6
Medium : https://medium.com/@thisara.damith
Blogspot : https://zynora00.blogspot.com/
.jpeg)
Comments
Post a Comment