The Setup
Apache as web server, PHP-FPM as PHP processor, connected over TCP on RHEL with SELinux enforcing.
Install the Stack
dnf install -y httpd php php-fpm
systemctl enable --now httpd php-fpmConfigure PHP-FPM for TCP
Edit /etc/php-fpm.d/www.conf:
listen = 127.0.0.1:9000Master this topic with hands-on labs
Go beyond reading — build real projects in sandboxed environments with expert video guidance.
Browse Courses →Configure Apache
Edit /etc/httpd/conf.d/php.conf:
<FilesMatch \.(php|phar)$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>Create a test page:
echo '<?php phpinfo();' > /var/www/html/index.phpThe SELinux Denial
curl http://localhost/index.php
# 503 Service UnavailableAVC log:
avc: denied { name_connect } for comm="httpd"
scontext=system_u:system_r:httpd_t:s0
tcontext=system_u:object_r:http_port_t:s0
tclass=tcp_socketIdentify the Fix
grep AVC /var/log/audit/audit.log | grep 9000 | audit2allow
#!!!! This avc can be allowed using one of these booleans:
# httpd_can_network_connect, httpd_graceful_shutdown
allow httpd_t http_port_t:tcp_socket name_connect;Get weekly IT automation tips
Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.
Subscribe Free →Apply the Fix
setsebool -P httpd_can_network_connect onVerify
curl http://localhost/index.php
# PHP info page rendersTCP vs Unix Socket
This lab uses TCP to demonstrate name_connect. Production setups often use Unix sockets with different SELinux checks (labels on the socket file).
Practice this exact scenario 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.
Related Articles
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.
SELinux Cheat Sheet for RHEL
Quick reference for essential SELinux commands on RHEL 9/10. Modes, contexts, labels, booleans, logs, and troubleshooting in one page.
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.
SELinux Booleans Explained
SELinux booleans let you toggle common service behaviors without writing custom policy. Learn getsebool, setsebool, and the most useful httpd booleans.
SELinux DAC vs MAC Explained
Understand the difference between Discretionary and Mandatory Access Control. Learn why MAC stops attacks that DAC cannot prevent.
SELinux File Contexts and Labels
Master SELinux file labeling with semanage fcontext and restorecon. The persistent labeling workflow every sysadmin needs to know.
Explore topics
Browse more articles on the topics covered here.