Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Mon Mar 12, 2012 10:05 am 
Offline
Senior Newbie

Joined: Sun Jan 29, 2012 2:34 pm
Posts: 15
Hi,

I have a php page that is attempting to open/create a file with fopen($fn, 'a').

When the file doesn't already exist it fails giving a "failed to open stream: Permission denied" message but if create an empty file first (touch as owner nginx) the script is able to write without problems to the file.

The directory is owner webc:webc and the permissions are 775, php is running as nginx which is in the webc group.

If i put the permissions on the directory to 777 it all works but I want to avoid this.

I've also tried this: set the directory to 777 let the script create the file (it is created with owner nginx as expected) then put the directory back to 775 - the script can still write to the file.....

why is it that create is failing but write works??

(selinux and php safe mode are disabled)

Anyone seen this before? Thanks


Last edited by flibble on Wed Mar 21, 2012 7:51 am, edited 1 time in total.

Top
   
 Post subject:
PostPosted: Mon Mar 12, 2012 6:43 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
Hmm... when you chmod 777 it and let fopen() create the file, what user/group is applied to it?

The reason for the different behavior for create vs. write is that creating a file requires writing to the directory (which is itself just a "file"); once it's created, the directory doesn't need to be written to and life goes on.

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
 Post subject:
PostPosted: Tue Mar 13, 2012 4:09 am 
Offline
Senior Newbie

Joined: Sun Jan 29, 2012 2:34 pm
Posts: 15
hoopycat wrote:
Hmm... when you chmod 777 it and let fopen() create the file, what user/group is applied to it?

The reason for the different behavior for create vs. write is that creating a file requires writing to the directory (which is itself just a "file"); once it's created, the directory doesn't need to be written to and life goes on.


Your explanation makes sense, and that's kind of how I expected the file system to work. When I leave the directory as 777 and let fopen create the file it's created as nginx:nginx

I specifically put nginx in my webc group so I was expecting a directory with ownership of webc:webc set to 775 would let nginx create files in it


Top
   
 Post subject:
PostPosted: Wed Mar 21, 2012 7:54 am 
Offline
Senior Newbie

Joined: Sun Jan 29, 2012 2:34 pm
Posts: 15
Solved the problem. My php-cgi processes had not been restarted since making the group modifications to my nginx user. From the shell everything seemed ok but these processes (several days later) were still with the 'old' environment.

I found out by running a exec('id' $out); echo $out[0]; to 'see' the truth.

doh!


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group