Question: 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');

```

Answer: 
You're editing the higher level directory, so the PHP user needs to have write access to that directory.
You must change the permissions of the folder and the files contained in it recursively. 
You need to do this from ssh as root user and then run the following command: 

```
chown -R www-data:www-data /directory/path/to/apply/chown

```

then you can execute the chown statement without any problems.

I found this way after researching, testing for several hours.

Remember that a folder or root owner file cannot be manipulated by another user (delete, rename, move, change properties), while root can do so above any user.

Best regards