2011-11-15 92 views
2

我有问题写入使用php的文本文件。这可能听起来很简单,但我已经将文件所有者和组设置为apache/root,对777的权限,我仍然无法写入文件。我使用php 5.3.8运行centos。php fopen无法打开流:权限被拒绝

==================== 
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 
+0

SELinux的极有可能阻止文件写入时,如果包含它的目录不具有RW上下文。 –

+0

你可能需要'chcon -t httpd_sys_rw_content_t/path/to/file' –

+0

我已经将包含该文件的目录设置为777并且对根目录/ apache以及..但仍然不起作用 – nuttynibbles

回答

5

为了允许目录是R/W,我使用的chcon命令到下它添加httpd_sys_script_rw_t类型的目录和任何内容:

chcon -R -t httpd_sys_script_rw_t <directory>

-R标志使命令的执行递归的。

-t标志将文件的扩展属性设置为指定的文件上下文。在这种情况下它时使用的httpd的文件上下文httpd_sys_script_rw_t

you want httpd_sys_script_exec_t scripts to read/write the data, and disallow other non sys scripts from access.

+0

我得到错误运行这个'缺少操作数' – Muhaimin

0

相应的文件上下文使用允许的httpd写入到磁盘(以及其他操作布尔)在httpd_selinux(8)手册页中描述。

相关问题