The Apache HTTP Server is a widely used web server across various Linux distributions, including CentOS, Red Hat, and Fedora. These distributions are popular in enterprise settings for their stability and reliability. Installing and configuring Apache on these platforms allows for a secure and efficient web server setup.

Setting up Apache on CentOS, Red Hat, or Fedora is a straightforward process. The package managers available in these distributions make the installation process simple and efficient. Configuring Apache afterward ensures the web server runs according to the specific needs of your environment.

Once Apache is installed and configured, it can serve web content reliably. You can also adjust the server settings to optimize performance and security. This setup is suitable for both simple static sites and more complex web applications.

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

  1. Launch terminal.
  2. Use the package manager to install the Apache package.
    $ 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
  3. Configure Apache by editing its configuration file.
    $ sudo vi /etc/httpd/conf/httpd.conf
  4. Test the configuration to ensure there are no 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 after making configuration changes.
    $ sudo systemctl restart httpd
  6. 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.
  7. Allow HTTP and HTTPS traffic through the firewall.
    $ sudo firewall-cmd --permanent --add-service=http --add-service=https
    success
  8. Reload the firewall to apply the new rules.
    $ sudo firewall-cmd --reload
    success
  9. Verify the Apache installation by accessing the server locally or remotely.
    $ 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.