Selinux, PHP, and HTTPD

on Oct. 1, 2013, 11:07 a.m.

A lot of tutorials say to disable selinux. This is dumb. here is how you configure it to let you serve php files.

first make sure it is actually selinux
echo 0 > /selinux/enforce
This disables selinux so now let us see if the pages serve up now.
Next if the pages serve fine with selinux disable, see what the policy is currently set on the directory
ls -Z
Also, you can check here to see if it is selinux that is keeping apache from executing the php files
tail /var/log/audit/audit.log
Next, we need to install some things to configure selinux
yum -y install policycoreutils-python
Next, lets configure it to work with the default directory
semanage fcontext -a -t httpd_sys_script_exec_t '/var/www/html/(/.*)?'
restorecon -R -v /var/www/html/
See if it changed the polcy
ls -Z
Re-enable selinux
echo 1 > /selinux/enforce