473,473 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

fopen for write fails

I'm having trouble opening a file for writing under Red Hat Fedora
Linux.

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
"root".

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

Thanks,
M. McDonnell

Dec 26 '05 #1
3 2745
What version of Fedora?

Do you have SELinux turned on?

less /etc/selinux/config

Look for SELINUX=enforcing

Izer

Dec 27 '05 #2
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.

Thanks,
M. McDonnell

Dec 27 '05 #3
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
works.

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.

Jan 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Loopy | last post by:
I'm trying to write a script that will connect to an external site so that I can get access referer information in a database on another one of my sites. I got errors, so I tried to write a script...
28
by: Sathyaish | last post by:
If fopen fails, is there a way to know why?
10
by: Longfellow | last post by:
Newbie here... My reading of the description of fopen() led me to expect that, with mode as "w", it would create a file if it did not exist. Checked the FAQ and did not see this question...
39
by: ferrad | last post by:
I am trying to open a file for appending. ie. if the file exists, open it for appending, if not, create it. I am getting back a NULL pointer, and do not know why. Here is my code: FILE...
25
by: subramanian100in | last post by:
Consider the following program: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { if (argc != 2) { printf("Usage: <program-name<text-file>\n");
16
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good)...
20
by: cscorley | last post by:
For some reason, I cannot use fopen() on the file in write mode. The file "time" is in the same directory as the .php file, with permissions set to 0766. PHP Version 5.2.5 Apache/2.2.8 code...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.