我想从主目录读取一些文件,我从其他服务器推送文件,我可以信任它。
我的index.php是/var/www/html/index.php
我想通过PHP的file_get_contents位于/home/user123/subdir/info.txt
如何从主目录中使用PHP读取文件(CentOS 7,Apache 2.4,SELinux)
我得到错误读取文件: file_get_contents(/home/user123/subdir/info.txt): failed to open stream: Permission denied (2)
aureport --avc
显示了拒绝错误
05.09.2014 14:17:16 httpd system_u:system_r:httpd_t:s0 6 dir getattr unconfined_u:object_r:user_home_dir_t:s0 denied 53606
我到目前为止试过的(没有成功):
chcon -R -t httpd_sys_script_rw_t /home/user123/*
chcon -R -t httpd_user_content_t /home/user123/*
添加目录到apache用户目录配置(/etc/httpd/conf.d/userdir.conf
)
<Directory "/home/user123/*">
AllowOverride None
Require all granted
</Directory>
我失去了什么/我到底做错了什么?
相关信息的系统:
Server version: Apache/2.4.6 (CentOS)
PHP version 5.4.16
SELinux enforcing
CentOS 7
UPDATE
授予apache的权限读取主目录从SELinux的
setsebool -P httpd_enable_homedirs on
解决了否认错误,但file_get_contents(/home/user123/subdir/info.txt): failed to open stream: Permission denied (2)
是STIL有...
你对'/家庭/ user123'至少'701'? Apache用户需要能够遍历它来列出内容。运行'chmod O + X /家庭/ user123'(那当然'O + r'上的目标文件) – 2014-09-05 12:56:19
(和+1解决您的SELinux的问题,而只是'setenforce 0'),它不应该是必要设置'正如你所做的那样,在/ home/user123中的所有内容上都有httpd_user_content_t',这可能会导致其他问题。相反,你可以将它设置在apache实际上将读取的目录中。'chcon -R -t httpd_user_content_t/home/user123/subdir'我使用这种方法。在设置'httpd_user_content_t'之前,要恢复主目录中的旧上下文'restorecon -R/home/user123'。 – 2014-09-05 12:59:53
最后注意到,虽然之前设置这方面'httpd_enable_homedirs'似乎没有做任何事情,我相信它_is_除了'httpd_enable_homedirs'实际需要。 – 2014-09-05 13:00:26