php chmod() not changing permissions php chmod() not changing permissions php php

php chmod() not changing permissions


The directory must be owned by the user invoking the script (typically www-data, apache or httpd if you're running the script in a apache/*NIX setup). A user can't set 777 permissions on directories it doesn't own.

See the note on the chmod() manual:

The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access. The mode can be changed only by user who owns the file on most systems.


First , open PHP error_report by adding two line on top of your code, see if there is a error coming from chmod:

ini_set('display_errors', true);error_reporting(E_ALL);

Make sure your WebServer has the permission to that directory, my guess is the WebServer don't have permission.


I was having similar troubles using chmod, although the file was owned by apache:apache (webserver user). In my case SELinux was getting in the way, disabling it made this clear:

sudo setenforce 0

And the chmod works. Now on to figuring out how to make a SELinux exception for this case...(and don't forget to enable SELinux, of course)