views:

2077

answers:

5

I chmod'ed the directory to 777, same with the directory contents. Still, I get a "permission denied" error. Does PHP throw this error if apache is not the group/owner, regardless of the file permissions? Here's the call that's failing:

rename('/correct/path/to/dir/1', '/correct/path/to/dir/2');
A: 

Try running the following script:

print_r(posix_getpwuid(getmyuid()));
print_r(pathinfo($YOUR_PATH));

And see what that returns.

Ross
+6  A: 

I believe you're editing the higher level directory, so the PHP user needs to have write access to that directory.

acrosman
+1  A: 

Thats probably because apache is not the owner of the parent directory. Renaming (or moving) a file is basically the same thing as creating a new file.

kjensen
A: 

to clarify, php can only rename directories it has actual ownership over:

-rwxrwxrwx user   user   temp/
-rwxr-xr-x apache apache temp2/
-rw-r--r-- user   user   script.php

assume script.php is trying to rename these two directories:

// this operation fails as PHP (running as apache) does not own "temp",
// despite having write permissions    
rename('temp', 'temp.bak');

// this operation is successful as PHP owns "temp2"
rename('temp2, 'temp.bak');
Owen
A: 

Another thing that might help these kinds of situations is to try actually lowering permissions. I've seen occasions where apache denies an application permission to do something because its permissions are set too high. My guess is that this is to encourage good security practice.

Jason Baker