So, you've installed httpd on CentOS, configured it, and are ready to go. After placing a test site in the /var/www/html directory, you see that everything opens and works, but you're going to have, say, several sites, and you want to store them not in the default directory but in some other one.
So, you create some other directory where the sites will live, configure the corresponding VirtualHost on the httpd server, and restart it. And what do you see? "403 - Access denied".
Having gone through everything possible, from plain chown and chmod (by the way, the owner should be set to apache:apache) to the <Directory "/mydir"> and "Allow from all" settings, you still don't achieve success.
Why?Because by default CentOS has a thing called SELinux enabled. I won't go into detail about what it is here. In short, it's a security system that doesn't allow services to work with things they don't need to work with by default. So for storing sites, CentOS and httpd by default use the path /var/www/html, and if the sites are located somewhere else, they won't work.
Solution.There are actually even four solutions:
1) Still store sites in /var/www/html, creating subdirectories for different sites.
2) Disable SELinux. Not recommended, but possible. To do this, run:
$ sudo setenforce 0
after which open the file /etc/sysconfig/selinux and change the value of the "SELINUX=" parameter to "disabled":
/etc/sysconfig/selinux:
SELINUX=disabled
SELINUXTYPE=targeted
SETLOCALDEFS=0
3) Disable SELinux only for Apache (httpd):
Run:
$ sudo setsebool -P httpd_disable_trans off
$ sudo /etc/init.d/httpd restart
4) Take the smart approach — allow Apache to work with sites outside of /var/www/html.
First, let's allow the Apache/httpd daemon, via the SELinux policy, to work with sites located outside the default directory:
$ sudo setsebool -P httpd_enable_homedirs on
And now let's set the required permissions for the directory where your sites will be located (in this example: /mywww):
$ sudo chcon -R -t httpd_sys_content_t /mywww
If Apache also needs to be granted write permissions
:
$ sudo chcon -R -t httpd_sys_rw_content_t /mywww
Applies to: CentOS 6
Comments