DEV Community

Cover image for Deploying an EC2 Instance with Apache: My Step-by-Step Journey
Morodolu Oluwafikunayomi
Morodolu Oluwafikunayomi

Posted on • Edited on

Deploying an EC2 Instance with Apache: My Step-by-Step Journey

Introduction:
Amazon EC2 (Elastic Compute Cloud) is one of AWS’s most powerful services — it lets you launch and manage virtual servers in the cloud. I recently set out to deploy an Apache web server on an EC2 instance to learn hands-on how to host a basic website from scratch.
This article walks through exactly how I did it, what challenges I faced (spoiler: port 22 drama!), and how I customized my first web page hosted on EC2.
What I Wanted to Do

  • Launch a Linux EC2 instance on AWS
  • Install and run Apache web server on it
  • Make the server publicly accessible
  • Add a custom message to the home page

Step-by-Step Deployment Process
Step 1: Launch an EC2 Instance:
Go to the AWS EC2 dashboard.
Click "Launch Instance"
-while in the launch instance page
-Name your server e.g MyfirstServer.

Image description

-Select the application and Amazon machine image(AMI) from the quick start or search their catalog
-I Choose Amazon Linux 2 AMI (or Ubuntu) for this tutorial,

Image description

-After that under instance type select t2.micro (free-tier eligible),do take not of the region in order to use t2.micro your region must be USA ,N.virginia.

Image description

-Next will be the key pair name, which is required, this serves as your passkey or passcode to access the instance or AMI, which is for security purpose, click on create a new key pair

Image description
-Then type the key pair name

  • There are different types of key pair type but for this tutorial we are going with RSA, what's the difference you might ask?

RSA: A well-established and widely used method that has been a cornerstone of online security for decades. Ed25519: A more modern and efficient approach, known for its speed and strong security with smaller key sizes
-choose the file type of the key as .pem for easy connection to the instance in command prompt using SSH.

Image description
-click on create key pair
-it will download to your computer, for safe keeping and will be later used in the SSH connection to the instance
-Then click on create instance.
-In the instance page click on the instance id

Image description

Step 2: Connect to Your Instance via SSH:
-Using gitbash type in the following one after the other

list the files the directory

ls

change directory to downloads

cd downloads

read permission, enabling them to view the contents of the file

chmod 400 keypairname
_note the the keypairname is the name assigned to the key pair or the name of the file _

connection via ssh

ssh -i "keypairname" ec2-user@ public ipv4 from the instance

Image description

_it should show

This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
type yes _

Image description

✅ Step 3: Install Apache
Once inside your EC2 shell:
type the following one after another;

Update packages

sudo yum update -y

Install Apache (httpd)

sudo yum install httpd -y

Start the Apache service

sudo systemctl start httpd

Enable Apache to run at boot

sudo systemctl enable httpd

✅ Step 4: Customize the Web Page
By default, Apache serves files from:
/var/www/html
So I created a custom homepage:

echo "<h1>Hello from My Apache EC2 Server 🚀</h1>" | sudo tee /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

Then I opened the browser and visited:
http://

Challenges I Faced:
SSH Timeout:

ssh: connect to host x.x.x.x port 22: Connection timed out
Enter fullscreen mode Exit fullscreen mode

Root cause: My ISP blocks outbound connections on port 22.
Solution: I used a VPN to bypass the ISP restrictions and connected to EC2 successfully.

Apache Not Visible from Browser:
Root cause: I forgot to allow HTTP (port 80) in the Security Group.

Solution: Added an inbound rule for HTTP in EC2's security group settings.

🧠 Conclusion & Lessons Learned
Deploying an Apache web server on EC2 taught me several key lessons:
Always check port rules when working in the cloud — Security Groups can silently block access
Network issues aren’t always your fault, sometimes your ISP gets in the way
EC2 gives full control, but that means you're responsible for everything: ports, firewalls, services, and configuration

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.