【发布时间】:2011-11-15 14:56:27
【问题描述】:
我在使用 php 写入文本文件时遇到问题。这听起来可能很简单,但我已将文件所有者和组设置为 apache/root,权限为 777,但我仍然无法写入文件。我正在使用 php 5.3.8 运行 centos。
====================
New info
====================
semanage fcontext -l | grep httpd | grep rw
/var/lib/drupal(/.*)? all files system_u:object_r:httpd_sys_script_rw_t:s0
/var/spool/gosa(/.*)? all files system_u:object_r:httpd_sys_script_rw_t:s0
/var/lib/bugzilla(/.*)? all files system_u:object_r:httpd_bugzilla_script_rw_t:s0
/var/spool/viewvc(/.*)? all files system_u:object_r:httpd_sys_script_rw_t:s0
【问题讨论】:
-
SELinux 很可能会阻止文件写入,如果包含它的目录没有 rw 上下文。
-
您可能需要
chcon -t httpd_sys_rw_content_t /path/to/file -
我已将包含文件的目录设置为 777 和 root/apache.. 但仍然无法正常工作
-
为了测试这个理论,以 root 身份运行
setenforce 0然后尝试运行脚本。如果成功,SELinux 就是问题所在。用setenforce 1重新打开它 -
是的,设置为 0 后它可以工作。我做了以下操作并得到以下错误:chcon -t httpd_sys_rw_content_t test.txt chcon: failed to change context of test.txt to root:object_r:httpd_sys_rw_content_t : 无效参数