Ubuntu – how to keep file and folder permissions from changing

permissionsPHPUbuntu

I have a directory of files and folders that are added and removed and the permissions that I had set keep changing. How can I permanently keep the permissions on a specific path so that no matter what happens in its folders all files and folders inside that folder will recursively follow the permissions set.

The permissions I had set is the following:

sudo chmod 755 -R /var/www/uploads
sudo chown www-data:www-data -R /var/www/uploads

I'm not sure what user group is used by php/apache when I write the code to delete the files and I'm guessing that would be why it cant do it.

Best Answer

Have you looked into using the umask command to set the permissions mask on the directory? There is a great explanation of the umask and how it works on Linux. I believe that correctly using umask and chmod should resolve the issue.