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
| Path | Purpose |
|---|---|
/etc/httpd/conf/httpd.conf | Main configuration |
/etc/httpd/conf.d/ | Virtual host definitions |
/var/www/html | Default 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
| Task | Ubuntu/Debian (apache2) | AlmaLinux/Rocky (httpd) |
|---|---|---|
| Package name | apache2 | httpd |
| Service name | apache2 | httpd |
| Config test | apache2ctl configtest | apachectl configtest |
| Enable module | a2enmod rewrite | Often 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.
Related Articles
- Understanding SELinux Basics on AlmaLinux/Rocky Linux
- How to Install PHP on AlmaLinux/Rocky Linux
- How to Set Up Let's Encrypt SSL on AlmaLinux/Rocky Linux
