Issue
I have setup a centos7 in virtualbox, in which runs apache httpd, mariadb, phpmyadmin etc, host is macos
when I try to map a url to a share folder, I encountered the error
Forbidden: You don't have permission to access /tutorial/ on this server.
sudo tail -f /var/log/httpd/error_log
[Wed Oct 19 22:48:23.108758 2016] [autoindex:error] [pid 1469] (13)Permission denied: [client 192.168.144.1:51847] AH01275: Can't open directory for index: /php-tutorial/www/
/etc/httpd/conf.d/tutorial.conf
Alias /tutorial "/php-tutorial/www"
<Directory "/php-tutorial/www">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
folder permissions are
drwxr-xr-x. 1 vagrant vagrant system_u:object_r:vmblock_t:s0 /php-tutorial/www
drwxr-xr-x. 1 vagrant vagrant system_u:object_r:vmblock_t:s0 /php-tutorial
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html
I am not sure whether this is possible, and if possible, what is the correct way to configure it.
Solution
Thanks for ezra-s for highlighting the possible problem.
Yes, it is because of the SELinux, because SELinux is enabled by default in Centos 7.2, which is the guest OS used here.
There are two different solutions for this problem:
Quick solution, disable SELinux
# vi /etc/selinux/config SELINUX=enforcing # <= change enforcing to disabled
Better solution, customise SELinux policies
# yum install -y policycoreutils-python # vi httpd_t.te module httpd_t 1.0; require { type httpd_t; type vmblock_t; class file { read getattr open }; } #============= httpd_t ============== allow httpd_t vmblock_t:file { read getattr open }; # checkmodule -M -m -o httpd_t.mod httpd_t.te # semodule_package -o httpd_t.pp -m httpd_t.mod # semodule -i httpd_t.pp # systemctl restart httpd
References:
- https://github.com/mitchellh/vagrant/issues/6970, someone encountered the same issue and found the way out step by step.
- https://wiki.centos.org/HowTos/SELinux, a good introduction about SELinux.
Answered By - David