Guides 11792 Published by

The tutorial explains how to install Apache from AlmaLinux 9’s default repositories, set it up as a service, and confirm that it is actually serving content. It begins with updating the system, enabling the AppStream repository if necessary, installing httpd via dnf, and starting the service immediately so it runs on boot. The guide then walks through opening port 80 (and optionally 443) in firewalld, testing access with curl, checking logs for errors, and even shows how to install mod_ssl, create a self‑signed certificate, and point Apache to those files. Finally it reminds you that you can drop your own HTML into /var/www/html or adjust the configuration to host static sites or PHP applications.



How to Install Apache (HTTPD) on AlmaLinux 9

You’ll learn how to pull the latest HTTP server straight from the default AlmaLinux 9 repos, spin it up as a service, and confirm that it’s actually serving content. No fluff—just the commands you need to run and why each one matters.

Step 1: Keep your system fresh
sudo dnf update -y

Updating first is critical because AlmaLinux 9 ships with a lot of security patches in its base image, but the latest Apache builds often depend on newer libraries. Without those, you’ll hit “dependency error” before you even get to start the server.

Step 2: Make sure the AppStream repo is enabled
sudo dnf config-manager --set-enabled appstream

I’ve seen people stumble here after a clean AlmaLinux install—AppStream is disabled by default on some minimal images, so `dnf install httpd` returns “No matching Packages found.” Enabling it gives you access to the full Apache package set.

Step 3: Install Apache (HTTPD)
sudo dnf install httpd -y

This pulls in the official `httpd` RPM along with all its runtime dependencies. No manual compilation required, and the package is signed so you can trust it’s unmodified.

Step 4: Enable and start the service
sudo systemctl enable --now httpd

Enabling makes sure Apache starts on boot; `--now` launches it immediately. If you forget this step, your server will sit idle until you manually run `systemctl start httpd`.

Step 5: Allow HTTP traffic through the firewall
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

AlmaLinux’s firewalld blocks everything by default. Adding the `http` service opens port 80; if you plan to use HTTPS, add `https` as well.

Step 6: Test that it’s working
curl -I http://localhost/

You should see a `200 OK` response. If not, check `/var/log/httpd/error_log` for clues. A common pitfall is the default SELinux context blocking Apache from reading your document root—run `restorecon -Rv /var/www/html` if you hit that.

Step 7 (optional): Secure with HTTPS
sudo dnf install mod_ssl
sudo systemctl restart httpd

After installing `mod_ssl`, Apache will listen on port 443. For a quick test, generate a self‑signed cert:

sudo mkdir -p /etc/pki/tls/certs
sudo openssl req -new -x509 -nodes -days 365 \
     -subj "/CN=localhost" \
     -keyout /etc/pki/tls/private/localhost.key \
     -out /etc/pki/tls/certs/localhost.crt

Then edit `/etc/httpd/conf.d/ssl.conf` to point at those files, reload Apache, and try `curl https://localhost`.

You now have a fully functional web server on AlmaLinux 9. Drop your own HTML into `/var/www/html`, tweak the config to suit your needs, and you’re ready to serve static sites or run PHP applications.