fopen permissions problem - PHP5 and RHEL4

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

Threaded View
Hi there,

I'm using fopen for the first time and I know I'm running into a
permissions problem, but I can't seem to resolve it and any help would
be greatly appreciated.

I'm running PHP5 and Apache on RedHat Enterprise Linux 4.

I've verified (by looking in httpd.conf) that Apache is running as
user "apache" and group "apache".  So, that's the user/group that PHP
should be running under, right?

The following line of code in my PHP file which, as I understand,
should open a pointer to a file, and create the file if it doesn't
exist (which it doesn't):
$writeFile = fopen($directory . $filename, "w");

This generates the following error:
Warning: fopen(/home/chroot/exports/webleads_200709261803.csv)
[function.fopen]: failed to open stream: Permission denied in /path/to/
filename.php on line 87

I've tried changing ownership of the /home/chroot/exports/ directory
to have the group be "apache" and then done a chmod 775 on the
directory.  Still get the error.

In fact, if I chmod 777 on the directory, thus giving every user
permission to write to the dir, I still get the error.  I totally
don't understand that...

Any help would be greatly appreciated.  I'm really at my wits end at
this point.



Re: fopen permissions problem - PHP5 and RHEL4

IamtheEvster wrote:
Quoted text here. Click to load it
well it seems weird.

Try (as root) going
# su apache
$ touch "pathtofilename"
  and see if that works.

If it does, I suspect PHP itself has some permssion stuff getting in the  
way. There I can't help..

Re: fopen permissions problem - PHP5 and RHEL4

Quoted text here. Click to load it

Well, If I try to su apache, then I get "The account is currently not

I believe, though, that that's because it's set to be an account that
can't log in.  In /etc/passwd, the home directory for the apache
account is /sbin/nologin.  If I change that to an actual directory
(one that apache does not have permission to, for example) then I

# su apache
su: /home/otheruser: Permission denied

Even if I try to assign permissions to all or to the apache user, I
get the permission denied error, so not sure what's going on there.

Where in PHP might there be some other permission-related items?  Are
there any settings in php.ini I should be looking at?

Thanks again for the help.


Re: fopen permissions problem - PHP5 and RHEL4

IamtheEvster wrote:
Quoted text here. Click to load it

Nope, nothing which would cause this problem.  open_basedir will limit  
directories you can access, but that wouldn't give you this problem.

I'd suggest you try a Linux admin group - figure out what your  
permission problems are.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline