Set up Apache HTTP Server (httpd)

How to set up Apache HTTP web server (httpd) in Linux.


Table of Contents

  1. Introduction
  2. Overview of httpd
  3. Prerequisites
  4. Implementation

1. Introduction

In this tutorial, we will configure an httpd webserver on RHEL-based Linux distributions to serve a simple webpage.

2. Overview of httpd

what is httpd?

  • Apache HTTP Server (httpd) is a web server that serves webpages to clients over HTTP/HTTPS.

Key Information

  • Purpose = Serve webpages.
  • Service or Package name = httpd
  • Configuration Files
    • /etc/httpd/conf/httpd.conf = Main configuration file.
    • /var/www/html/index.html = Default webpage.
  • Log Files = /var/log/httpd/
  • access_log = Records client requests.
  • error_log = Records server errors.

3. Prerequisites

  • Linux server (RHEL / AlmaLinux)
  • Internet connectivity (for package installation)

4. Implementation

  1. check if the httpd package is already installed
    rpm -qa | grep httpd
  2. Install httpd
    dnf install httpd -y
  3. Start and Enable the httpd service
    systemctl enable --now httpd
  4. Explore the configuration file
    cat /etc/httpd/conf/httpd.conf

    Important parameters:

    • Listen 80 = Defines the port Apache listens on.
    • DocumentRoot = Defines the directory where website files are stored.
    • IncludeOptional conf.d/*.conf = Loads additional configuration files from the conf.d directory.
  5. Explore the Default Webpage Location

    Apache uses the following directory by default:

    /var/www/html/

    The default webpage:

  6. Create your first webpage

    Open the default webpage:

    vi /var/www/html/index.html

    Add the following HTML content:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Structure of HTML Document</title>
        <style>
            body {
                margin: 0;
                min-height: 100vh;
                display: grid;
                place-content: center;
                text-align: center;
                background: #000;
                color: #fff;
                font-family: Georgia, serif;
            }
            h1 { font-size: 3rem; font-weight: 400; letter-spacing: 1px; margin: 0; }
            p  { color: #aaa; font-size: 1.1rem; margin-top: 1rem; }
        </style>
    </head>
    <body>
        <!-- Main content of website -->
        <h1>Welcome to My First Website</h1>
        <p>Thanks for visiting my website &lt;3</p>
    </body>
    </html>
  7. Restart the httpd service
    systemctl restart httpd
  8. Access Your Website

    Open your browser and enter:

    http://<Public-IP>

    You should see your first webpage.

  9. Configure the Firewall / Security Group

    If you are using AWS EC2, add an inbound security group rule:

    Type Protocol Port Source
    HTTP TCP 80 0.0.0.0/0

    For HTTPS later, use TCP port 443.

    If using an OS firewall such as firewalld, allow HTTP too:

    firewall-cmd --permanent --add-service=http
    firewall-cmd --reload