Installing the Apache HTTP Server (httpd) provides a standard, well-supported way to serve websites and internal applications on CentOS, Red Hat, and Fedora. A correct base setup avoids common first-run problems like a service that starts but is unreachable due to firewall policy.

On these distributions, Apache is delivered as the httpd package and managed as the systemd unit httpd.service. Most server-wide settings live in /etc/httpd/conf/httpd.conf, while additional configuration and module snippets are commonly loaded from /etc/httpd/conf.d.

A working setup depends on three moving parts lining up: a valid configuration (checked with apachectl configtest), a running service (managed with systemctl), and network policy that permits inbound HTTP and HTTPS (typically firewalld). When serving content outside the default document root or listening on non-standard ports, SELinux contexts and port labeling may also need updates to prevent silent access denials.

Steps to install and configure Apache on CentOS, Red Hat or Fedora:

  1. Open a terminal with sudo privileges.
  2. Install the Apache package using the system package manager.
    $ sudo dnf install --assumeyes httpd
    [sudo] password for user:
    Updating Subscription Management repositories.
    Unable to read consumer identity
    
    This system is not registered with an entitlement server. You can use subscription-manager to register.
    
    CentOS Stream 9 - BaseOS                        483 kB/s | 8.6 MB     00:18
    CentOS Stream 9 - AppStream                     886 kB/s |  16 MB     00:18
    CentOS Stream 9 - Extras packages               862  B/s |  14 kB     00:16
    Dependencies resolved.
    ================================================================================
     Package                 Architecture Version              Repository      Size
    ================================================================================
    Installing:
     httpd                   aarch64      2.4.57-5.el9         appstream       47 k
    Installing dependencies:
     apr                     aarch64      1.7.0-11.el9         appstream      121 k
     apr-util                aarch64      1.6.1-23.el9         appstream       96 k
     apr-util-bdb            aarch64      1.6.1-23.el9         appstream       13 k
     centos-logos-httpd      noarch       90.4-1.el9           appstream      252 k
     httpd-core              aarch64      2.4.57-5.el9         appstream      1.3 M
     httpd-filesystem        noarch       2.4.57-5.el9         appstream       14 k
     httpd-tools             aarch64      2.4.57-5.el9         appstream       80 k
    Installing weak dependencies:
     apr-util-openssl        aarch64      1.6.1-23.el9         appstream       15 k
     mod_http2               aarch64      1.15.19-5.el9        appstream      145 k
     mod_lua                 aarch64      2.4.57-5.el9         appstream       59 k
    
    Transaction Summary
    ================================================================================
    Install  11 Packages
    
    Total download size: 2.2 M
    Installed size: 11 M

    On older CentOS releases that still use yum, replace dnf with yum.

  3. Configure Apache by editing its main configuration file.
    $ sudo vi /etc/httpd/conf/httpd.conf

    Setting a global ServerName (for example, ServerName example.com) suppresses the common fully-qualified domain name warning during config tests.

  4. Test the configuration for syntax errors.
    $ sudo apachectl configtest
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::e5f:4565:1b9c:6e87. Set the 'ServerName' directive globally to suppress this message
    Syntax OK
  5. Restart the httpd service to apply the configuration.
    $ sudo systemctl restart httpd
  6. Verify the httpd service is running.
    $ sudo systemctl is-active httpd
    active
  7. Enable the httpd service to start automatically on boot.
    $ sudo systemctl enable httpd
    Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

    Using systemctl enable --now httpd starts the service immediately while enabling it.

  8. Allow HTTP and HTTPS traffic through the firewall.
    $ sudo firewall-cmd --permanent --add-service=http --add-service=https
    success

    When firewalld is not installed or not used, apply equivalent rules in the active firewall stack.

  9. Reload the firewall to apply the new rules.
    $ sudo firewall-cmd --reload
    success
  10. Verify the Apache installation by requesting the default page locally.
    $ curl 127.0.0.1
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.7.28">
      <title>HTTP Server Test Page powered by CentOS</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      <link rel="shortcut icon" href="http://www.centos.org/favicon.ico">
    ##### snipped #####
Discuss the article:

Comment anonymously. Login not required.