Install & Configure Apache HTTP Server on AlmaLinux

By Raman Kumar

Updated on Aug 05, 2024

In this tutorial, we'll Install & Configure Apache HTTP Server on AlmaLinux 9 and securing the website using Let's Encrypt Certbot.

The Apache HTTP Server, commonly referred to as Apache, is a powerful, flexible, and widely-used web server software. Developed and maintained by the Apache Software Foundation, it is an open-source project available for free. Apache is known for its rich feature set, reliability, and versatility, making it a popular choice for hosting websites and web applications.

Key Features of Apache HTTP Server:

Modular Architecture: Apache's modular design allows administrators to load and unload modules as needed, extending the server's functionality without altering the core code.

Cross-Platform: Apache runs on a wide range of operating systems, including various flavors of Unix/Linux, Windows, and macOS.

Virtual Hosting: Apache supports both IP-based and name-based virtual hosting, allowing multiple websites to be hosted on a single server.

Security: Apache offers robust security features, including SSL/TLS support, authentication modules, and access control mechanisms.

Flexibility: Apache's extensive configuration options and support for various programming languages (such as PHP, Python, and Perl) make it highly adaptable to different use cases.

Community and Support: Being an open-source project, Apache boasts a large community of users and developers who contribute to its ongoing development and provide support through forums, mailing lists, and documentation.

Install & Configure Apache HTTP Server on AlmaLinux

Prerequisites

  • A AlmaLinux 9 installed dedicated server or KVM VPS
  • A root user access or normal user with administrative privileges
  • Basic Linux command knowledge

Step 1: Update System Packages

First, update your system packages to ensure everything is up to date.

sudo dnf update -y

Step 2: Install Apache HTTP Server

Install the Apache HTTP Server package using the dnf package manager.

sudo dnf install httpd -y

Start the Apache service and enable it to start on boot.

sudo systemctl start httpd
sudo systemctl enable httpd

Step 3: Configure Firewall

Allow HTTP and HTTPS traffic through the firewall.

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

Step 4: Verify Apache Installation

You can verify that Apache is running by opening your web browser and navigating to your server's IP address or hostname. You should see the Apache default welcome page.

http://your-server-ip

Step 5: Configure Apache

Create a directory to hold your website's files. Replace your_domain with your domain name.

sudo mkdir -p /var/www/your_domain/public_html
sudo chown -R apache:apache /var/www/your_domain/public_html

Create a sample index.html file.

nano /var/www/your_domain/public_html/index.html

Add the following content:

<html>
    <head>
        <title>Welcome to Your Domain!</title>
    </head>
    <body>
        <h1>Success! The your_domain virtual host is working!</h1>
    </body>
</html>

Create a new virtual host configuration file.

sudo nano /etc/httpd/conf.d/your_domain.conf

Add the following content, replacing your_domain with your actual domain name:

<VirtualHost *:80>
    ServerAdmin webmaster@your_domain
    DocumentRoot "/var/www/your_domain/public_html"
    ServerName your_domain
    ServerAlias www.your_domain
    ErrorLog "/var/log/httpd/your_domain-error_log"
    CustomLog "/var/log/httpd/your_domain-access_log" common

    <Directory "/var/www/your_domain/public_html">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Test the Apache configuration for syntax errors.

sudo apachectl configtest

If you see Syntax OK, restart Apache.

sudo systemctl restart httpd

Step 6: Secure using SSL

Install Certbot, the tool for managing Let's Encrypt SSL certificates.

sudo dnf install certbot python3-certbot-apache -y

Now, let's obtain SSL Certificate

Run Certbot to obtain and install the SSL certificate. Replace your_domain with your actual domain name.

sudo certbot --apache -d your_domain

Follow the prompts to complete the installation. Certbot will automatically configure Apache to use the new SSL certificate.

Test SSL Configuration

After Certbot completes the process, test the SSL configuration.

sudo apachectl configtest

If you see Syntax OK, restart Apache to apply the changes.

sudo systemctl restart httpd

Certbot automatically sets up a cron job for renewing your certificates. To ensure this is set up correctly, you can test the renewal process with a dry run.

sudo certbot renew --dry-run

If you don't see any errors, the automatic renewal is configured correctly.

Step 7: Access Your Web Server

Your Apache HTTP Server should now be up and running. You can access it via your web browser by navigating to your domain name.

https://your_domain

That's it! We have successfully seen how to install and configure Apache HTTP Server on AlmaLinux 9.