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
        umask 022

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.

  • Mine says $UID -gt 199 instead of $UID -gt 99 thats the only difference – JMC Jan 19 '12 at 21:26
  • That doesn't really matter - what this block is doing is testing to see if the uid is > 99 (or in your case 199), and if the username and the group name are the same. For an RPM installed apache, the apache user has the uid and gid of 48, meaning that the first test fails, so the umask should be 022 (the bottom half of the if statement), because the first test will fail. Either way, though, it looks like something else in your config is changing the umask after this block runs (if it runs at all). – malcolmpdx Jan 19 '12 at 21:38
  • Places to start looking: what shell is your apache user using? Are there any shell scripts (.bashrc, .bashprofile, .profile) in it's home directory? Any umask statements in it's init script? What is root's umask? – malcolmpdx Jan 19 '12 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.