2011-11-15 90 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)手冊頁中描述。

相關問題