fopen for write fails

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm having trouble opening a file for writing under Red Hat Fedora

Here is the statement:

$fp = fopen("/var/www/html/test01.txt","w");

It generates the following error msg:

fopen(/var/www/html/test01.txt): failed to open stream: Permission
denied in /var/www/html/buildhw.php on line 11

Here are the permission settings for the directories and the file that
I'm trying to open:

drwxrwxrwx   25 root root  4096 Aug 13 12:57 var
drwxrwxrwx   11 root root  4096 Aug 13 13:12 www
drwxrwxrwx    2 root root  4096 Dec 26 13:19 html
-rwxrwxrwx    1 mike mike    22 Dec 26 13:17 test01.txt

Here is some more info:

1. Logging in as root makes no difference - still get the same error.

2. If I change the mode from "w" to "r", fopen works. This tells me
that PHP can at least find the file.

3. I can do an fopen on the same file from C,  with a mode of "w", and
it works. This implies that it's not a permission issue, but rather
something in PHP or Apache.

4. The account named "apache" is a member of the groups "mike" and

I must apologize if this is a silly question; I'm new to Linux, PHP,
and Apache. Any help would be greatly appreciated.

M. McDonnell

Re: fopen for write fails

What version of Fedora?

Do you have SELinux turned on?

less /etc/selinux/config

Look for SELINUX=enforcing


Re: fopen for write fails

Thanks for your help. Hopefully I've answered your two questions below.
Hope you can help; I've run out of ideas...

1. Regarding the Fedora version, here's what I get back from the
command "uname  -a".
"Linux McDonnell 2.6.9-1.667 #1 Tue Nov 2 14:41:25 EST 2004 i686 athlon
i386 GNU/Linux"

2. I looked at /etc/selinux/config, and saw "SELINUX=enforcing"  (it
was uncommented, so I assume it's on). Listed below is what I got back
from the command "getsebool -a" (I assume these are the boolean flags
related to SELinux).

allow_ypbind --> active: 1 pending: 1
dhcpd_disable_trans --> active: 0 pending: 0
httpd_disable_trans --> active: 0 pending: 0
httpd_enable_cgi --> active: 1 pending: 1
httpd_enable_homedirs --> active: 1 pending: 1
httpd_ssi_exec --> active: 1 pending: 1
httpd_unified --> active: 1 pending: 1
named_disable_trans --> active: 0 pending: 0
named_write_master_zones --> active: 0 pending: 0
nscd_disable_trans --> active: 0 pending: 0
ntpd_disable_trans --> active: 0 pending: 0
portmap_disable_trans --> active: 0 pending: 0
snmpd_disable_trans --> active: 0 pending: 0
squid_disable_trans --> active: 0 pending: 0
syslogd_disable_trans --> active: 0 pending: 0
ypbind_disable_trans --> active: 0 pending: 0

Any help would be greatly appreciated.

M. McDonnell

Re: fopen for write fails

Sorry for the delay.  You should probably turn off SELinux unless you
are sure you need it.  Maybe someone who is more knowladgable about
SELinux could help you out however I always turn it off since it causes
me lots of problems due to my lack of understanding of how SELinux

SELinux is a security system though and by disabling it you will be
reducing the security of your system to hackers.  I however have turned
it off on many machines and made sure the standard filesystem security
systems where setup good.  I have luckily not had an issue so far.

Site Timeline