The Apache HTTP Server is a popular web server that runs on Linux platforms, including CentOS, Red Hat, and Fedora. These distributions are known for their stability, making them ideal in enterprise environments. Installing Apache provides a robust platform for serving static files, dynamic content, and complex web applications.

Package managers on these systems streamline the installation of Apache, and various modules can be added for enhanced functionality. Adjusting configuration files enables fine-tuning of performance parameters, security settings, and virtual host arrangements. The Apache ecosystem also integrates well with systemd, ensuring manageable service control and logging.

Maintaining a reliable Apache environment involves routine log monitoring, timely software updates, and awareness of security implications such as SELinux configurations. Proper firewall rules and regular performance checks help keep the server efficient and secure. This approach supports both production workloads and development environments across multiple use cases.

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.