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

SELinux Upload Directories Guide

Properly label writable upload directories for Apache with SELinux. Use httpd_sys_rw_content_t to allow writes without disabling security.

Luca BertonMarch 25, 20261 min read

The Problem

Your PHP app needs to write uploaded files. DAC permissions are correct but uploads fail. The AVC log reveals:

avc: denied { write } for comm="httpd"
scontext=system_u:system_r:httpd_t:s0
tcontext=unconfined_u:object_r:httpd_sys_content_t:s0
tclass=file

httpd_sys_content_t is read-only. Apache can read but not write.

Related Course

Master this topic with hands-on labs

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

Browse Courses →

The Solution: httpd_sys_rw_content_t

LabelPermissions
httpd_sys_content_tRead-only
httpd_sys_rw_content_tRead + Write
httpd_sys_script_exec_tExecute (CGI)

Step-by-Step

1. Create the upload directory

mkdir -p /srv/webroot/upload
chown apache: /srv/webroot/upload/

2. Quick test

chcon -t httpd_sys_rw_content_t /srv/webroot/upload

3. Make it persistent

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

4. Verify

ls -Zd /srv/webroot/upload
system_u:object_r:httpd_sys_rw_content_t:s0 /srv/webroot/upload
Stay Updated

Get weekly IT automation tips

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

Subscribe Free →

Why Separate Labels Matter

Only directories that need writes get httpd_sys_rw_content_t. This limits damage if an attacker exploits a vulnerability — they can only write to the upload directory, not the entire webroot.

Anti-Pattern

# DON'T: Makes everything writable
chcon -t httpd_sys_rw_content_t -R /srv/webroot

Only label directories that need writes.

Practice 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.