chrizonline
chrizonline

Reputation: 4979

php fopen failed to open stream: Permission denied

i'm having problem writing to a text file using php. this might sound simple but i've set the file owner and group to apache/root, permission to 777 and i'm still unable to write to file. i'm running centos with php 5.3.8.

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

Upvotes: 3

Views: 8206

Answers (2)

chrizonline
chrizonline

Reputation: 4979

To allow the directory to be r/w, i used the chcon command to add the httpd_sys_script_rw_t type to the directory and anything under it:

chcon -R -t httpd_sys_script_rw_t <directory>

The -R flag makes the command recursive.

The -t flag sets the extended attribute on the file to the specified file context. In this case the httpd file context httpd_sys_script_rw_t which is used when:

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

Upvotes: 8

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798516

The appropriate file contexts to use for allowing HTTPd to write to disk (as well as booleans for other operations) are described in the httpd_selinux(8) man page.

Upvotes: 0

Related Questions