DEV Community

Cover image for Deploying a Static Website on Amazon EC2 with Apache HTTP Server
Swarali Chine
Swarali Chine

Posted on

Deploying a Static Website on Amazon EC2 with Apache HTTP Server

Introduction
Amazon EC2 (Elastic Compute Cloud) is one of the core compute services in AWS, providing scalable virtual servers that can host websites, applications, and enterprise workloads. While AWS offers several managed hosting options, understanding how to manually configure a web server on EC2 provides a strong foundation in Linux administration, networking, and cloud infrastructure.

In this project, I launched an Amazon EC2 instance running Amazon Linux 2023, installed the Apache HTTP Server, and deployed a custom static website. Along the way, I learned how Security Groups control network access, how Apache serves web content, and how AWS services work together to host a web application.

Why Build This Project?
Understanding how web applications are hosted on a virtual server is a fundamental cloud engineering skill. Although managed services simplify deployments, manually configuring a web server helps build a deeper understanding of compute, networking, operating systems, and web server administration.
This project demonstrates how to:

  • Launch and configure an Amazon EC2 instance
  • Secure access using AWS Security Groups
  • Install and manage Apache HTTP Server
  • Deploy a static HTML website
  • Understand how HTTP requests are processed
  • Practice responsible AWS resource management

Architecture

AWS Services Used in This Project
Amazon EC2
Amazon EC2 (Elastic Compute Cloud) provides resizable virtual servers in the cloud. I used EC2 to host the Apache web server and deploy the static website. It gives complete control over the operating system, networking, storage, and server configuration, making it an excellent service for learning cloud infrastructure.
Amazon Linux 2023
Amazon Linux 2023 is an AWS-optimized Linux distribution designed for running applications on Amazon EC2. I selected it because it is lightweight, secure, regularly updated, and integrates seamlessly with AWS services. It also uses the dnf package manager, making software installation and maintenance straightforward.
Amazon EBS
Amazon Elastic Block Store (EBS) provides persistent block storage for Amazon EC2 instances. In this project, the root EBS volume stored the operating system, Apache installation, configuration files, and website content. The website files remained available throughout the lifetime of the EC2 instance.
Security Groups
Security Groups act as virtual firewalls that control inbound and outbound traffic for EC2 instances. I configured inbound rules to allow SSH access only from my IP address for secure administration and HTTP access on port 80 so users could access the hosted website through a browser.
Apache HTTP Server
Apache HTTP Server is one of the world's most widely used open-source web servers. I installed Apache on the EC2 instance to process incoming HTTP requests and serve the custom HTML webpage stored in the server's document root.

Step 1: Launch an EC2 Instance
I launched an EC2 instance using the Amazon Linux 2023 Amazon Machine Image (AMI) and selected a micro instance type suitable for a learning environment.

To securely access the server while making the website publicly available, I configured the following Security Group rules:
SSH (Port 22) → My IP
HTTP (Port 80) → Anywhere (0.0.0.0/0)

Step 2: Connect to the Instance
I connected to the instance using EC2 Instance Connect and verified the environment before installing Apache.
Some of the first commands I executed were:
whoami
cat /etc/os-release
pwd
These commands confirmed the current user, operating system version, and working directory.

Step 3: Install Apache HTTP Server
After updating the operating system packages, I installed Apache using the Amazon Linux package manager.
sudo dnf update -y
sudo dnf install httpd -y
Once the installation completed, I started the Apache service and configured it to start automatically whenever the EC2 instance boots.
sudo systemctl start httpd
sudo systemctl enable httpd
I also verified that the service was running successfully.

Step 4: Deploy the Website
Apache serves website files from its default document root:
/var/www/html
I replaced the default Apache welcome page with a custom index.html file and restarted the Apache service.
sudo systemctl restart httpd
After opening the EC2 instance's public IPv4 address in a web browser, my custom website was successfully displayed.

Step 5: Verify Apache Configuration
To better understand how Apache works, I explored its configuration and log files.
To locate the configured document root:
grep -n "DocumentRoot" /etc/httpd/conf/httpd.conf
To review recent HTTP requests:
sudo tail -10 /var/log/httpd/access_log
These commands helped me understand where Apache stores website content and how incoming requests are recorded for monitoring and troubleshooting.

Key Takeaways
This project provided practical experience with:

  • Launching and managing Amazon EC2 instances
  • Understanding Amazon Linux 2023
  • Installing and configuring Apache HTTP Server
  • Configuring AWS Security Groups
  • Managing Linux services using systemctl
  • Understanding the Apache document root
  • Reading Apache access logs
  • Deploying a static website on AWS More importantly, it strengthened my understanding of how compute, networking, storage, and web server software work together to deliver a web application.

Cost Optimization
To keep the project cost-effective, I followed several AWS cost optimization practices:

  • Used a micro EC2 instance suitable for learning
  • Used the default root EBS volume
  • Avoided provisioning unnecessary AWS resources
  • Terminated the EC2 instance immediately after completing the project
  • Verified that associated resources were cleaned up to prevent ongoing charges Managing cloud costs is an important aspect of building production-ready AWS solutions, even for small learning projects.

GitHub Repository
The complete project, including source code, documentation, architecture diagrams, and screenshots, is available on GitHub.
Repository:
https://github.com/swaralichine/aws-projects/tree/main/01-web-hosting-and-deployment/03-ec2-apache-web-server

Final Thoughts
Building and deploying a website on Amazon EC2 provided a hands-on introduction to the core building blocks of AWS infrastructure. While the application itself is simple, the project demonstrates several fundamental cloud concepts, including virtual machines, networking, Linux administration, persistent storage, and web server configuration.

For anyone beginning their AWS learning journey, this project offers an excellent opportunity to understand what happens behind the scenes when hosting a website in the cloud. These foundational skills serve as the basis for more advanced architectures involving load balancing, auto scaling, containers, and highly available applications.

Top comments (0)