Skip to main content
🎤 Luca Berton is speaking at Red Hat Summit & KubeCon EU 2026!Learn more →
Back to Blog

Fix SELinux Apache Custom Webroot

Step-by-step guide to fix SELinux 403 Forbidden errors when using a custom Apache DocumentRoot like /srv/webroot on RHEL.

Luca BertonMarch 22, 20261 min read

The Problem

You move Apache's DocumentRoot to /srv/webroot. Permissions are fine, config is valid. But:

curl http://localhost/index.html
# 403 Forbidden
Related Course

Master this topic with hands-on labs

Go beyond reading — build real projects in sandboxed environments with expert video guidance.

Browse Courses →

Why It Happens

Files under /var/www are labeled httpd_sys_content_t. Custom paths get var_t:

matchpathcon /srv/webroot /var/www
/srv/webroot	system_u:object_r:var_t:s0
/var/www	system_u:object_r:httpd_sys_content_t:s0
Stay Updated

Get weekly IT automation tips

Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.

Subscribe Free →

Step-by-Step Fix

1. Create the webroot

mkdir -p /srv/webroot
echo "SELinux Test" > /srv/webroot/index.html

2. Configure Apache

DocumentRoot "/srv/webroot"
<Directory "/srv/webroot">
    AllowOverride None
    Require all granted
</Directory>

3. Quick test with chcon

chcon -t httpd_sys_content_t -R /srv/webroot
curl http://localhost/index.html
# SELinux Test

4. Make it permanent

semanage fcontext -a -t httpd_sys_content_t '/srv/webroot(/.*)?'
restorecon -Rv /srv/webroot

5. Verify new files inherit correctly

touch /srv/webroot/newfile.html
ls -Z /srv/webroot/newfile.html
# httpd_sys_content_t

The Complete Workflow

  1. matchpathcon — discover the expected label
  2. semanage fcontext -a — define the persistent mapping
  3. restorecon -Rv — apply labels from policy
  4. Verify with ls -Z

Build muscle memory for this in our SELinux for System Admins course.

---

Ready to go deeper? Check out our hands-on course: SELinux for System Admins — practical exercises you can follow along on your own machine.

Ready to learn by doing?

Stop reading tutorials — start building. Expert video courses with hands-on labs in real sandboxed environments.

Share this article
LB
Luca Berton

Docker Captain, IT automation expert, Red Hat Summit & KubeCon speaker. Building hands-on education for DevOps engineers at CopyPasteLearn.

Related Articles

Explore topics

Browse more articles on the topics covered here.