How can I set the default permissions for files uploaded by apache2?
Apache inherits its umask
from its parent process (i.e. the process starting Apache).
This should typically be the /etc/init.d/{apache,httpd}
script.
So you can put a umask command in that script.
# echo "umask 002" >> /etc/init.d/httpd
and then:
# /etc/init.d/httpd restart
Or you can also run this command:
# echo "umask 002" >> /etc/sysconfig/httpd
and then
# /etc/init.d/httpd restart
Related videos on Youtube
Nikita240
Updated on September 18, 2022Comments
-
Nikita240 over 1 year
When I upload files through php, it writes the file with the permissions 644 (-rw-r--r--).
I have my /var/www/html folder setup with setgid, so that all files uploaded are set to a group that should be allowed explicit access (FTP, etc). However, 644 permissions do not allow the group of the file to write, which is a problem.
How can I configure apache2, so that all files/directories created by www-data within the /var/www/html folder have the permissions 775 (-rwxrwxr-x) set to them?
I am running Ubuntu 14.04 on a DigitalOcean VM with Apache 2.2.
-
Brian C about 6 yearsThese solutions add a umask line to the end of the script, which mostly isn't helpful. The sysconfig version will likely work (as the file is sourced/read by the init.d script); the init.d version will not work (as httpd has already been started, so the umask at end of the file comes too late to have any effect). Regardless, adding a line at the end of a script often doesn't work as the script may contain an "exit" which stops the line being seen (you may have checked for this, if so, understood).