DEV Community

Oluwatobiloba Oludare
Oluwatobiloba Oludare

Posted on

How I Deployed an EC2 Instance with Apache: A Step-by-Step Guide 🚀

As someone learning cloud computing and DevOps, one of my first hands-on experiences was launching an Amazon EC2 (Elastic Compute Cloud) instance and deploying a basic web server using Apache. If you are new to AWS or cloud infrastructure in general, this post will walk you through the process I followed—from spinning up an EC2 instance to seeing my first “It works!” page live on a browser.

What is EC2?
Amazon EC2 (Elastic Compute Cloud) is a service that provides resizable compute capacity in the cloud. In simpler terms, it lets you rent virtual machines (called instances) where you can run your applications, host websites, or do pretty much anything you'd do on a physical server—without actually managing hardware.

With EC2, you can:

  • Choose your preferred OS (Linux, Windows, etc.)
  • Scale up or down depending on traffic
  • Pay only for what you use

Now, let’s dive into how I used EC2 to set up a web server with Apache.

Step-by-Step: Deploying EC2 with Apache

  1. Login to AWS Console Go to https://aws.amazon.com/ and sign in to the AWS Management Console. If you don’t have an account yet, sign up—it’s free to get started and comes with a 12-month Free Tier, which includes EC2.

Image description

2. Launch an EC2 Instance
Search for EC2 under the “Services” menu

Image description

3. Click Launch Instance.

Image description

4. Give your instance a name (e.g., My-Server);

Amazon Machine Image (AMI): Choose Amazon Linux

Image description

5. Change your country to N.Virginia

Image description

6. Instance Type: Select t2.micro or t3.micro (eligible for the free tier)

Image description

7. Key Pair: Click on create new key pair.

Image description

8. **As shown below, give your keypair a name and select RSA as your key pair type; seclect .pem as key file format, then click "create key pair". It will download instantly.**

Image description

9. Security Group:
Create a new Security Group with the following:
Type: SSH | Port: 22 | Source: 0.0.0.0/0
Type: HTTP | Port: 80 | Source: 0.0.0.0/0

Image description

10. Then click Launch Instance and wait for the instance status to be running.

Image description

11. click on the instance as shown below

Image description

12. Connect to the Instance via SSH

Open Git Bash (or PowerShell/Terminal); navigate to where you downloaded your keypair (using cd) then give it the right permission of "chmod 400 your-key-name.pem" as shown below

Image description

13. Go back to your AWS dashboard and click on the box beside your server's name, then copied the public ip address.

Image description

14. Connect using SSH:
Use this format ssh -i "my-ec2-key.pem" ec2-user@.

Insert your keypair name & your public IPv4 address you copied and press enter.

Image description

Type yes when prompted

15. Install a Web Server (Apache)

Run the following commands in the EC2 terminal:

sudo yum update -y
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd

Image description

Image description

16. Verify in Browser- Open your browser and type the Public IPv4 address of your EC2 instance. You should see the default Page with a message that says:

It works!

🎉 Congratulations! You’ve successfully deployed a web server on EC2.

Image description

17. Customize the Page:
To customize the page, run this command in the EC2 terminal:

Image description

you can replace the Hello from EC2 to any sentence you want eg Assignment Completed Successfully!

Image description

Once again, Congratulation.

The Challenge I Faced and How I Solved it

  • Apache Not Showing in Browser Problem: After installing Apache, typing the EC2 public IP in the browser showed nothing or timed out.

Solution:

  • I went back to my EC2 terminal and I discovered that I have not enabled the Apache.
  • I immediately start and enable it using "sudo systemctl start httpd" & "sudo systemctl enable httpd".Thereafter, the Apache welcome page loaded correct ly.

đź§© Conclusion
Deploying an EC2 instance and setting up Apache was a rewarding hands-on experience that deepened my understanding of cloud infrastructure and server configuration. From launching the instance to configuring security groups and troubleshooting connectivity issues, each step taught me something new about how cloud environments operate.

This beginner-friendly project reminded me that even small deployments can build the confidence and skills needed for more complex DevOps tasks ahead. If you're just getting started with AWS or cloud engineering, I highly recommend trying this out—you’ll gain practical insights that no tutorial can fully explain until you do it yourself.

Thanks for reading! If you have any questions, ran into different challenges, or want to share your own experience, feel free to drop a comment below. Let’s learn together! 🙌

Top comments (0)