Set Up Apache Web Server (httpd) on RHEL 10
Install and configure Apache httpd on RHEL 10: dnf, systemctl, firewalld, virtual hosts, SELinux labels, mod_ssl HTTPS, reverse proxy, hardening.
To set up Apache on RHEL 10, install the httpd package with dnf, start it with systemctl enable --now httpd, and open the http and https services in firewalld. Put site files under /var/www with the correct SELinux label, add name-based virtual hosts in /etc/httpd/conf.d/, enable TLS with mod_ssl, then test with apachectl configtest.
This guide walks through each step on a fresh RHEL 10 server, including the SELinux and firewall parts that cause most "it works on port 80 but not for my site" problems. If you have not prepared the server yet (registration, updates, a non-root admin user), follow our RHEL 10 first-time setup guide first.
Key takeaways
- On RHEL the Apache package and service are both called
httpd. Main config:/etc/httpd/conf/httpd.conf; drop-in files:/etc/httpd/conf.d/*.conf. - Open the firewall with
firewall-cmd --permanent --add-service=http --add-service=https, then reload. - SELinux stays enforcing. Label custom web roots with
semanage fcontextandrestorecon, and use booleans such ashttpd_can_network_connectfor reverse proxies. - Install
mod_sslfor HTTPS. It creates a self-signed certificate for testing; replace it with a real certificate before going live. - Always run
apachectl configtestbeforesystemctl reload httpd. - Red Hat notes that the RHEL 10 httpd unit applies extra systemd hardening, such as a read-only
/home, so serving files from user home directories needs a deliberate override.
Before you start
| Requirement | How to check |
|---|---|
| RHEL 10 registered and repositories enabled | sudo subscription-manager status and dnf repolist (BaseOS and AppStream) |
| A user with sudo rights | sudo -v |
| Static IP or DNS name for the server | ip -br addr, hostnamectl |
| firewalld running | sudo firewall-cmd --state |
| SELinux enforcing | getenforce |
If dnf repolist is empty, see configuring RHEL 10 repositories. For DNS records pointing at this server, our DNS and DHCP on RHEL 10 guide covers BIND.
Step 1: install httpd
sudo dnf install -y httpd
rpm -q httpd
httpd -v
httpd comes from the AppStream repository. httpd -v prints the exact Apache 2.4 build shipped with your minor release. Optional modules are separate packages: mod_ssl for TLS, mod_security for a web application firewall, and so on.
Step 2: start and enable the service
sudo systemctl enable --now httpd
systemctl status httpd --no-pager
sudo ss -tlnp | grep httpd
You should see httpd listening on port 80. Browsing to the server from the machine itself (curl -I http://localhost) returns the RHEL test page until you add your own content.
Step 3: open the firewall
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-services
The predefined http service is TCP port 80 and https is TCP port 443. If the server has several zones, add --zone=public (or the right zone) to each command. Our firewalld commands guide explains zones and rich rules if you need to limit access by source address.
Step 4: understand the file layout
| Path | Purpose |
|---|---|
/etc/httpd/conf/httpd.conf | Main configuration. Leave most of it alone and add your own files instead. |
/etc/httpd/conf.d/ | Site and feature configs, loaded in alphabetical order. ssl.conf and welcome.conf live here. |
/etc/httpd/conf.modules.d/ | LoadModule lines, one file per module group. |
/var/www/html/ | Default document root. |
/var/log/httpd/ | access_log and error_log, plus per-site logs you define. |
/etc/pki/tls/ | Default location for certificates and keys. |
To see what Apache actually loaded:
httpd -M # loaded modules
httpd -S # parsed virtual hosts and which is default
Step 5: create a name-based virtual host
One server can host several sites on the same IP address. Apache picks the site by the Host header. Create a directory and a test page:
sudo mkdir -p /var/www/shop.example.com/public
echo '<h1>shop.example.com works</h1>' | sudo tee /var/www/shop.example.com/public/index.html
sudo mkdir -p /var/log/httpd/shop.example.com
Then add /etc/httpd/conf.d/shop.example.com.conf:
<VirtualHost *:80>
ServerName shop.example.com
ServerAlias www.shop.example.com
DocumentRoot /var/www/shop.example.com/public
<Directory /var/www/shop.example.com/public>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ErrorLog /var/log/httpd/shop.example.com/error.log
CustomLog /var/log/httpd/shop.example.com/access.log combined
</VirtualHost>
Content under /var/www inherits the httpd_sys_content_t SELinux label, so this example works without SELinux changes. The custom log directory under /var/log/httpd inherits httpd_log_t for the same reason.
Test and reload:
sudo apachectl configtest
sudo systemctl reload httpd
curl -H 'Host: shop.example.com' http://localhost/
The first virtual host Apache reads for a given address and port becomes the default for requests that match no ServerName. httpd -S shows which one that is. Many admins add a 000-default.conf catch-all that returns a plain page, so unknown host names never land on a real site.
Name-based, IP-based or port-based virtual hosts?
| Type | How Apache picks the site | When to use it |
|---|---|---|
| Name-based | The Host header (and SNI for HTTPS) matched against ServerName and ServerAlias | The normal choice: many sites on one IP address |
| IP-based | The local IP address the request arrived on, for example <VirtualHost 192.0.2.10:80> | When each site must have its own address, such as separate firewall rules |
| Port-based | The port, for example an admin site on 8443 | Internal tools; needs a Listen line, a firewall rule and an SELinux port label |
For a port-based site on 8443, the port is already in SELinux's http_port_t list on RHEL, so you only add Listen 8443 https and open the port with firewall-cmd --permanent --add-port=8443/tcp. For other ports, label them first with semanage port as shown in the next step. Since modern browsers and TLS clients all send SNI, name-based hosting also works for HTTPS with a separate certificate per site.
Step 6: SELinux for custom paths and features
Keep SELinux enforcing. When a site fails with "403 Forbidden" and file permissions look fine, SELinux is the usual reason. Check for denials:
sudo ausearch -m AVC -ts recent
sudo journalctl -t setroubleshoot --since "10 min ago"
Common fixes:
| Situation | Command |
|---|---|
| Web root outside /var/www, for example /srv/web | sudo semanage fcontext -a -t httpd_sys_content_t "/srv/web(/.*)?" then sudo restorecon -Rv /srv/web |
| App must write uploads to a directory | sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/shop.example.com/uploads(/.*)?" then restorecon |
| Apache as reverse proxy to a backend port | sudo setsebool -P httpd_can_network_connect on |
| Apache connecting to a remote database | sudo setsebool -P httpd_can_network_connect_db on |
| Listen on a non-standard port such as 8081 | sudo semanage port -a -t http_port_t -p tcp 8081 |
| Web content on an NFS share | sudo setsebool -P httpd_use_nfs on |
Avoid chcon for permanent changes, because a later restorecon or relabel will undo it. Our SELinux in RHEL 10 guide explains contexts and booleans in more depth. If you serve shared content from NFS, set up the export first with our NFS server and client guide for RHEL 10.
Step 7: enable HTTPS with mod_ssl
sudo dnf install -y mod_ssl
sudo systemctl restart httpd
mod_ssl adds /etc/httpd/conf.d/ssl.conf with a default virtual host on port 443 and a self-signed certificate for testing. For a real site, get a certificate from your CA (or from Let's Encrypt using an ACME client; certbot is available from EPEL, not from the RHEL repositories) and add a TLS virtual host:
<VirtualHost *:443>
ServerName shop.example.com
DocumentRoot /var/www/shop.example.com/public
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/shop.example.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/shop.example.com.key
ErrorLog /var/log/httpd/shop.example.com/ssl_error.log
CustomLog /var/log/httpd/shop.example.com/ssl_access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName shop.example.com
Redirect permanent / https://shop.example.com/
</VirtualHost>
Replace the port 80 block from Step 5 with the redirect block shown here. Keep the private key readable only by root (chmod 600). Certificates under /etc/pki/tls already carry the cert_t label; if you copy them in from elsewhere, run restorecon -Rv /etc/pki/tls.
RHEL sets TLS protocol and cipher defaults through system-wide crypto policies rather than per-application settings. Check the active policy with update-crypto-policies --show, and change it system-wide instead of hard-coding SSLProtocol lines unless you have a specific reason.
Step 8: basic hardening
Create /etc/httpd/conf.d/security.conf:
ServerTokens Prod
ServerSignature Off
TraceEnable Off
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
- Remove the welcome page once your own default site exists:
sudo mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.disabled. - Turn off modules you do not use by commenting their lines in
conf.modules.d. - Add
Strict-Transport-Securityonly after HTTPS works for every host name, because browsers cache it. - Keep the server patched with
dnf upgrade, and read our RHEL 10 hardening guide for the operating system side.
Optional: Apache as a reverse proxy
Many RHEL web servers do not serve files at all. They terminate TLS and pass requests to an application on a local port, such as a Node.js, Java or Python service on 8080. The proxy modules are loaded by default in the RHEL httpd package; confirm with httpd -M | grep proxy.
<VirtualHost *:443>
ServerName api.example.com
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/api.example.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/api.example.com.key
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
RequestHeader set X-Forwarded-Proto "https"
</VirtualHost>
Then allow httpd to make outbound connections, or SELinux returns a 503:
sudo setsebool -P httpd_can_network_connect on
sudo apachectl configtest && sudo systemctl reload httpd
The boolean lets httpd connect to any port. If you want something narrower, read the AVC denial with ausearch -m AVC and check the port labels with semanage port -l | grep http; RHEL's SELinux documentation explains the port types httpd may use.
Optional: PHP with php-fpm
Red Hat's RHEL 10 documentation describes running PHP through FastCGI with php-fpm as the default process manager. Install and start it:
sudo dnf install -y php php-fpm
sudo systemctl enable --now php-fpm
sudo systemctl restart httpd
echo '<?php echo "PHP works"; ?>' | sudo tee /var/www/shop.example.com/public/info.php
curl -H 'Host: shop.example.com' http://localhost/info.php
The package adds /etc/httpd/conf.d/php.conf, which hands .php files to php-fpm over a Unix socket. Delete the test file once you have checked it works.
Performance basics
RHEL's httpd uses the event MPM by default, which handles keep-alive connections with fewer threads than the older prefork model. Check with httpd -V | grep -i mpm. For most servers, the defaults are fine until monitoring shows a limit. When it does, tune these in a file such as /etc/httpd/conf.d/mpm-tuning.conf:
| Directive | What it controls | When to change it |
|---|---|---|
MaxRequestWorkers | Maximum simultaneous requests being served | Requests queue while CPU and memory are free |
ServerLimit and ThreadsPerChild | Processes and threads per process; their product caps MaxRequestWorkers | When raising MaxRequestWorkers |
KeepAliveTimeout | How long idle keep-alive connections stay open | Many idle connections holding resources |
Timeout | How long Apache waits on slow clients or backends | Slow backends behind a reverse proxy |
Enable compression with mod_deflate for text responses, and let a CDN or browser caching headers (mod_expires) handle static assets. Change one setting at a time and measure.
Step 9: logs and monitoring
sudo tail -f /var/log/httpd/shop.example.com/error.log
sudo journalctl -u httpd --since today
For quick health data, enable mod_status on a location restricted to localhost or your monitoring network, and scrape it with the Prometheus Apache exporter or your monitoring agent. Log rotation for the default logs is configured in /etc/logrotate.d/httpd. Read the path pattern in that file: if it only matches files directly in /var/log/httpd/, logs in per-site subdirectories need their own logrotate entry.
Troubleshooting
| Symptom | Likely cause | Check |
|---|---|---|
| Browser times out from other machines, curl localhost works | Firewall | firewall-cmd --list-services |
| 403 Forbidden on a custom path | SELinux label or missing Require all granted | ls -Z, ausearch -m AVC |
| httpd fails to start after editing config | Syntax error | apachectl configtest, journalctl -u httpd |
| "Address already in use" | Another service on port 80 or 443 | ss -tlnp |
| Wrong site shown for a host name | ServerName mismatch, default vhost order | httpd -S |
| Reverse proxy returns 503 | SELinux blocks outbound connections | getsebool httpd_can_network_connect |
| Files in /home/user/public_html not served | SELinux plus the RHEL 10 unit's read-only /home | Move content to /var/www or /srv, or use a reviewed systemd drop-in |
Automating the setup with Ansible
Once the manual steps work, describe them in a playbook so every server is built the same way:
- name: Apache web server on RHEL 10
hosts: web
become: true
tasks:
- name: Install httpd and mod_ssl
ansible.builtin.dnf:
name: [httpd, mod_ssl]
state: present
- name: Deploy virtual host
ansible.builtin.template:
src: shop.example.com.conf.j2
dest: /etc/httpd/conf.d/shop.example.com.conf
notify: Reload httpd
- name: Check Apache syntax
ansible.builtin.command: apachectl configtest
changed_when: false
- name: Start and enable httpd
ansible.builtin.systemd_service:
name: httpd
state: started
enabled: true
- name: Open http and https
ansible.posix.firewalld:
service: "{{ item }}"
permanent: true
immediate: true
state: enabled
loop: [http, https]
handlers:
- name: Reload httpd
ansible.builtin.systemd_service:
name: httpd
state: reloaded
The syntax check runs before the handler, so a broken template fails the play instead of reloading Apache with a bad config. The ansible.posix collection must be installed on the control node for the firewalld module.
Installing and securing services such as httpd with firewalld and SELinux is standard practice in our Linux administration training and RHCSA training, held in our Kharadi, Pune classroom and live online.
Frequently asked questions
What is the Apache package called on RHEL 10?
It is called httpd. Install it with sudo dnf install httpd, and manage it with systemctl as the httpd service.
Where are the Apache configuration files on RHEL 10?
The main file is /etc/httpd/conf/httpd.conf. Site and feature configs go in /etc/httpd/conf.d/, and module load lines are in /etc/httpd/conf.modules.d/.
How do I open the firewall for Apache?
Run firewall-cmd --permanent --add-service=http and --add-service=https, then firewall-cmd --reload. These services map to TCP ports 80 and 443.
Why do I get 403 Forbidden on my custom document root?
Usually SELinux. Files outside /var/www need the httpd_sys_content_t label: add it with semanage fcontext and apply it with restorecon. Also check that the Directory block has Require all granted.
How do I enable HTTPS on Apache in RHEL 10?
Install mod_ssl, restart httpd, then add a VirtualHost on port 443 with SSLEngine on and your certificate and key paths. Redirect port 80 to HTTPS once it works.
Should I disable SELinux to make Apache work?
No. Find the denial with ausearch or setroubleshoot, then fix it with the right file label, port label or boolean. SELinux limits damage if the web application is compromised.
How do I check Apache configuration before reloading?
Run apachectl configtest, which should print Syntax OK. Then use systemctl reload httpd so existing connections are not dropped.
Can Apache serve sites from users' home directories on RHEL 10?
Red Hat's RHEL 10 notes say the httpd unit mounts /home read-only by default, and SELinux also restricts home content. Keep site content in /var/www or /srv instead.
References
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0