I need files created by apache2 to have umask 002
, i.e. group rw, by default.
I've tried putting umask 002
in /etc/apache2/envvars and although this script does get executed as part of apache start up (apache2ctl graceful
) the umask has no effect. Presumably somewhere further in the start up process (e.g. when the user is downgraded from root
to www-data
) there's somewhere better to put this.
I've read posts about Fedora and one suggesting putting umask in /etc/init.d/apache2
but neither of these apply/work in Debian (Squeeze).
Can you help?
To be sure that the umask setting takes effect please use a simple test and do not use any other web application for this. It might be the case that these application change the rights independently from the umask setting of Apache.
Simple test PHP script:
Take care that the user www-data has write access to the folder where you have installed this simple test file.
To have the new umask running, check if the file /etc/apache2/envvars will be used within your Apache start file /etc/init.d/apache2 :
Set your umask in /etc/apache2/envvars :
Restart your Apache :
Check the difference :
If you run multiple sites you can set default group permission using Access Control Lists (ACL) per directory like so:
Set
setid
flag to force all new files to inherit group from directory:Make new files have
rw
for the group permissions, ex. so thatwww-data
can write to files SFTPed by the upload user:Confirm the ACL is like so:
Create a file to confirm it worked:
(For Debian Stretch that uses systemd - Thanks womble!)
Put
UMask=0002
in the Apache2 systemd service unit file, reload the service unit, and then restart Apache2.