How To Install Apache (HTTPD) on Amazon Linux 2

Published: May 25, 2023 (Updated: May 25, 2023)

Enjoying this content? Subscribe to the Channel!

Lightning Fast: Install Apache (HTTPD) on Amazon Linux 2 (The Easy Way)


Hi there, it’s Darren O’Neil from Darren’s Tech Tutorials!

If you’re running a server on Amazon Web Services (AWS) and need a reliable web server up and running fast, Apache is often the go-to choice. It’s stable, versatile, and incredibly easy to install, especially on Amazon Linux 2.

In this quick guide, we’re going to walk through the few simple commands needed to get the Apache web server (known as httpd in the Linux world) installed, started, and ready to serve traffic on your EC2 instance.

Note: While this guide is focused on Amazon Linux 2, the steps and commands are identical for most Red Hat-based distributions, including CentOS, Fedora, and RHEL.


Prerequisites

Before we jump into the terminal, make sure you have the following ready:

  1. An Amazon Linux 2 EC2 Instance: You should be successfully logged in via SSH.
  2. Security Group Configuration: For the world to see your web server, you must ensure that your EC2 instance’s Security Group has an inbound rule allowing traffic on Port 80 (HTTP). Without this, the verification step will fail!

Step 1: Installing the HTTPD Package

On Amazon Linux 2 and other RHEL-based systems, the Apache web server package is named httpd. We will use the yum package manager to install it.

Open your terminal and execute the following command:

sudo yum install httpd -y

The -y flag tells the installer to automatically accept the installation prompts, making the process seamless. The installation should complete in just a few seconds!


Step 2: Starting and Verifying the Apache Service

Once the files are installed, the service needs to be started. We’ll use systemctl (the modern service manager) to handle this, though older service commands also work.

2a. Start the Service

Execute the command to bring the web server online:

sudo systemctl start httpd

2b. Check the Status

Always verify that the service is running correctly:

sudo systemctl status httpd

You should see an output confirming that the service is active (running).


Step 3: Enabling Apache on Server Reboot

If your EC2 instance reboots (perhaps due to maintenance or scheduled downtime), you want Apache to automatically start up again so your website doesn’t disappear.

We use the systemctl enable command to ensure the service persists across reboots:

sudo systemctl enable httpd

This command links the service to the system startup routine, ensuring that your web server is always ready when your server comes back online.


Step 4: Verifying the Installation in a Browser

Now for the moment of truth! We need to confirm that the server is listening for external connections.

  1. Navigate to your AWS EC2 console.
  2. Select your instance and copy the Public IPv4 Address (or the Public DNS name).
  3. Paste this address into a new tab in your web browser.

Success!

If everything is configured correctly (especially Port 80 in the Security Group), you will see the default Apache HTTP Server Test Page. This confirms that Apache is fully installed and serving content from your Amazon Linux 2 instance!


Conclusion and Next Steps

And there you have it—a lightning-fast method for installing Apache on Amazon Linux 2! Whether you’re setting up a simple landing page or preparing for a complex application deployment, these four steps are all you need to get your foundational web server running on AWS.

If you found this guide helpful, please be sure to like this post and subscribe to Darren’s Tech Tutorials for more clear, accessible technology guides. If you ran into any issues or have questions, drop a comment below—I’m always happy to help!

Happy coding!