File Permissions created by Apache
OS: CentOs
Whenever apache (apache2) creates a file or directory it automatically sets the permissions to 777. I want it's directories to be 775 and files 664. How can I fix this?
Put umask 002
in the end of /etc/sysconfig/httpd
and restart httpd (service restart httpd
) and it should do the trick for future files. Apache inherits the umask from its parent process, so this setup makes that happen.
Set the umask
for apache (or whatever user it runs under):
umask 002
will provide you with 775 and 664 on new folders and files.
Check /etc/bashrc. It should already (at least on a CentOS machine) have the following stanzas:
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# By default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi
This should already be getting you the behavior you want, unless you installed a custom apache, and created the apache user yourself. Even then, it shouldn't be getting 000 as the umask unless that's already explicitly set up somewhere. I mention this only because your system is exhibiting signs of a non-standard config, and because of that, it's possible that other users (system or otherwise) are also getting this far too broad file creation mask.