Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
thanks for the additional info –  JMC Jan 19 '12 at 20:19
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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