How to Install Apache (httpd) on AlmaLinux/Rocky Linux

On RHEL-family distributions, Apache is packaged as httpd rather than apache2 — a naming difference that trips up administrators coming from Ubuntu/Debian. This guide covers the full installation and configuration.

Prerequisites

  • AlmaLinux 9 or Rocky Linux 9 VPS
  • Root or sudo access

Step 1 — Install httpd

sudo dnf install httpd -y

Step 2 — Enable and Start

sudo systemctl enable --now httpd

Step 3 — Allow HTTP/HTTPS Through firewalld

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

Step 4 — Test in a Browser

http://YOUR_SERVER_IP

Key File Locations

PathPurpose
/etc/httpd/conf/httpd.confMain configuration
/etc/httpd/conf.d/Virtual host definitions
/var/www/htmlDefault document root (same as Ubuntu/Debian)
/var/log/httpd/Logs

Creating a Virtual Host

sudo nano /etc/httpd/conf.d/example.com.conf
<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/example.com/html

    ErrorLog /var/log/httpd/example.com-error.log
    CustomLog /var/log/httpd/example.com-access.log combined
</VirtualHost>
sudo apachectl configtest
sudo systemctl restart httpd

Handling SELinux for Custom Web Roots

sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/example.com/html(/.*)?"
sudo restorecon -Rv /var/www/example.com/html

Enabling mod_rewrite (Often Needed for PHP Apps)

Unlike Ubuntu/Debian's a2enmod, RHEL-family httpd typically has mod_rewrite compiled in and loaded via the main config already — verify:

httpd -M | grep rewrite

Adding PHP Support

sudo dnf install php php-mysqlnd -y
sudo systemctl restart httpd

Allowing httpd Network Connections (For Proxy Configurations)

sudo setsebool -P httpd_can_network_connect 1

Adding SSL with Certbot

sudo dnf install epel-release -y
sudo dnf install certbot python3-certbot-apache -y
sudo certbot --apache -d example.com

Quick Reference: apache2 vs httpd

TaskUbuntu/Debian (apache2)AlmaLinux/Rocky (httpd)
Package nameapache2httpd
Service nameapache2httpd
Config testapache2ctl configtestapachectl configtest
Enable modulea2enmod rewriteOften built-in; verify with httpd -M

Common Errors

403 Forbidden despite correct permissions — SELinux context issue; apply the semanage fcontext/restorecon commands above.

"Could not reliably determine the server's fully qualified domain name" — harmless warning; set ServerName in the main config to silence it.

Continue Reading

Browse more articles in AlmaLinux & Rocky Linux.

  • httpd, apache almalinux, apache rocky linux, rhel apache
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

AlmaLinux vs Rocky Linux vs CentOS: What Happened to CentOS?

If you're choosing a RHEL-compatible Linux distribution for your VPS, understanding the CentOS...

How to Get Started with AlmaLinux/Rocky Linux on a VPS

This guide covers the essential first steps after deploying a new AlmaLinux or Rocky Linux VPS...

How to Use dnf: The Package Manager for AlmaLinux & Rocky Linux

dnf (Dandified YUM) is the package manager for AlmaLinux, Rocky Linux, and other RHEL-family...

How to Configure firewalld on AlmaLinux/Rocky Linux

firewalld is the default firewall management tool on AlmaLinux and Rocky Linux, using a...

How to Install Nginx on AlmaLinux/Rocky Linux

This guide covers installing and configuring Nginx on AlmaLinux or Rocky Linux, including the...