How to Install Apache on AlmaLinux 9

  • Francis Ndungu

Introduction

Apache is a popular, open-source web server software that is widely used across the globe. Its flexibility, performance, and security features make it a preferred choice for hosting websites and web applications. AlmaLinux 9 is a free, open-source Linux distribution that provides a stable and secure platform for running various applications. Combining Apache with AlmaLinux 9 ensures a reliable web server setup suitable for different environments.

This article explains how to install Apache on AlmaLinux 9.

Prerequisites

To follow along with this guide, ensure you've:

Install Apache

Installing Apache on AlmaLinux 9 involves several steps. First, you need to ensure your server is up-to-date, then install the Apache package. Finally, you'll check the installed Apache version to confirm successful installation.

  1. Update the server packages to the latest version to ensure compatibility and security.

    CONSOLE
    $ sudo dnf update
    
  2. Install Apache using the dnf package manager.

    CONSOLE
    $ sudo dnf install httpd -y
    
  3. Verify the installation by checking the Apache version.

    CONSOLE
    $ httpd -v
    

Manage Apache Service

Managing the Apache service ensures that the web server is running correctly and is set to start on boot.

  1. Start the Apache service and enable it to run on boot

    CONSOLE
    $ sudo systemctl start httpd
    
  2. Enable the Apache Service to start at boot.

    CONSOLE
    $ sudo systemctl enable httpd
    
  3. Stop Apache Service**

    CONSOLE
    $ sudo systemctl stop httpd
    
  4. Restart Apache Service.

CONSOLE
$ sudo systemctl restart httpd
  1. Check Apache Service Status.

    CONSOLE
    $ sudo systemctl status httpd
    

Configure Apache

Apache uses various files to control its settings. You should familiarize yourself with these files to know how to customize the webserver setup and troubleshoot issues as they occur. Here are the key Apache configuration files:

  • Main Configuration File: /etc/httpd/conf/httpd.conf
    • Define global settings and modules.
  • Virtual Hosts Configuration: /etc/httpd/conf.d/
    • Configure different websites on the same server.
  • Document Root Directory: /var/www/html/
    • Store website files and content.
  • Error Log: /var/log/httpd/error_log
    • Record server errors and issues.
  • Access Log: /var/log/httpd/access_log
    • Log all requests made to the server.

Allow Necessary Ports Through the Firewall

To access your Apache web server, you need to allow HTTP and HTTPS ports through the firewall.

  1. Allow HTTP (Port 80)through the firewall.

    CONSOLE
    $ sudo firewall-cmd --permanent --add-service=http
    
  2. Allow the HTTPS (Port 443) through the firewall.

    CONSOLE
    $ sudo firewall-cmd --permanent --add-service=https
    
  3. Reload the firewall to load the new changes.

    CONSOLE
    $ sudo firewall-cmd --reload
    

Run a Sample Website

Running a sample website helps to confirm that your Apache server is working correctly.

  1. Create an HTML file in the document root directory of your web server.

    CONSOLE
    $ sudo nano /var/www/html/index.html
    
  2. Enter the following information into the file

    HTML
    <HTML>
      <body>
        <h1>Welcome to Apache on AlmaLinux 9</h1>
      </body>
    </html>"
    
  3. Access the sample Website by visiting the following URL on a web browser, such as chrome. Replace 192.168.0.1 with your server's public IP address.

    http://192.168.0.1
    

Conclusion

This article shows you how to install Apache on AlmaLinux 9. You have also managed the Apache service using systemctl, learned how to configure the necessary settings. Additionally, you have allowed the necessary ports through the firewall and run a sample website. To enhance your experience, consider exploring advanced Apache configurations such as setting up SSL certificates, and optimizing the webserver performance.

  • Databases
  • Webservers
  • PHP
  • API
  • Python
  • VPS Guides
  • Network
  • AI
  • Node.js