Hugo Fouquet Hugo Fouquet - 4 months ago 10x
PHP Question

Unable to write file with 0775

When I want upload an image on my server, my script doesn't have the rights for write this file.

However, my script is execute localy and the rights of the folder are 0775.

...# chmod -R 0775 img
drwxrwxr-x 2 root root 4096 Jun 11 10:56 img

But, when I put the rights in 0777, it's work. There he has a solution for not allowing to everyone to write to my directory ?

Thanks !


The upload directory needs to be owned by the user that will write the file (in this case the user the web server process is running under) or the upload directory needs to have group ownership for a group of which the web server process user is a member.

So for example if the webserver user is apache and the web server user is a member of group apache, you could solve this by

chown apache /path/to/upload/directory


chgrp apache /path/to/upload/directory

Any script running on the webserver will then have write access to the upload directory.