Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using CentOS on a virtual dedicated server.

When I go in as root, and change the chmod value of a folder it works. But, any files I place into that folder do not inherit the chmod I set.

This is what I used:

chmod -Rv 777 files

the return was this:

mode of `files' retained as 0777 (rwxrwxrwx)
mode of `files/1344188366-f7cad6aa87685db775817d4168c329ef-AUTO_INSURANCE2.csv'
changed to 0777 (rwxrwxrwx)

Okay so one file changed. But if I place any files into that folder they will have a different chmod value. How do I make chmod stick with every file and folder within that directory?

The files I want default chmod set to are being uploaded through XHR. I.E a file upload process from browser to server.

How do I set the chmod level on the application code in my PHP?


I think I have found a reasonable solution to my problem. The answer below solves the file permission issue. But after running get_current_user() in php, I realized the user the script is running under is different than the user that the files I am trying to work on. The file user is apache because that's who created it. But the PHP script is a different user, the default user.

share|improve this question

closed as not constructive by ewwhite, Ward, Michael Hampton, gWaldo, EEAA Aug 14 '12 at 0:34

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

So you want everyone in the whole world to be able to change all your files whenever they want? This is not secure. – Michael Hampton Aug 5 '12 at 17:49
1. NEVER chmod 777. 2. Google: SGID. – quanta Aug 5 '12 at 17:50
I know I know, but the server itself is isolated and no one can access it. Those who can should be able to 777. Thanks for the concern though. – please delete me Aug 5 '12 at 17:51
Why do you want the mode 777 for a csv file anyway? Try as root chmod 1777 files and then upload a file. Is that what you want? – ott-- Aug 5 '12 at 19:12
So far you haven't even really said what problem you're trying to solve. You're too fixated on your chosen "solution" which unfortunately is the "wrong" solution for so many reasons it would take a book to list them all. You'll make progress when you take a step back and look more carefully at what you're trying to do (and maybe tell the rest of us). – Michael Hampton Aug 6 '12 at 0:13
up vote 5 down vote accepted

You'll need to modify the umask instead. This can be defined per-user (in ~/.profile) or system-wide (i.e. /etc/profile).

A great breakdown of this concept and use-cases is available here.

A more detailed breakdown of the unmask and octal permissions is available here.


Your specific issue is how to set permissions on files uploaded via PHP through Apache. THe same concept of umask applies, except it needs to be defined in the right place. On a typical Apache installation, that place would be the environment variables file; envvars on some distributions. /etc/sysconfig/httpd on RHEL/CentOS.

Also see: How to override default permissions for files stored by Apache/PHP in /tmp?

share|improve this answer
This depends heavily on what you're doing and who's accessing the system. If you're doing this all as the root user, that's typically bad practice. Please use a non-root user. But what you're looking for can be accomplished with umask 000. Try entering that command, then doing the file creation/actions you need, and see if the behavior is what you want. If it is, you could place umask 000 in your user's login script. – ewwhite Aug 5 '12 at 18:04
I tried > umask000 chmod -Rv 777 files but it didn't work. It changed the permission for the files currently in the directory to 777, but, did not take effect for future files. – please delete me Aug 5 '12 at 18:10
This probably won't work for root because the umask setting is overridden in /etc/profile. You should be doing the work on your VPS as another user, if possible. Also, how are your "future files" being created? If it's FTP, for example, there may need to be a change to the umask settings on your FTP server. – ewwhite Aug 5 '12 at 18:13
I tried using a different, non root user, with the same line but still no dice. Just the default 644 chmod setting. The files are being uploaded through XHR. – please delete me Aug 5 '12 at 18:16
When adding context to the question, please try to update the question and rephrase it accordingly so all of the information is in one place. Don't litter the comment list with bits and pieces. – Henk Langeveld Aug 5 '12 at 19:09

What you will need to do is set the group permissions on that folder...

setting it up like a collaborative folder:

chmod 2777 /what/ever/folder

That way any file placed in the folder takes on the group settings by default


setfacl -m d:g:whatever-group:rwx /what/ever/folder
share|improve this answer
Yeah I tried that also. I also tried setting the umaks in all these directories /etc/profile<br/> /etc/bashrc<br/> /etc/sysconfig/httpd<br/> /etc/init.d/rc.d/httpd<br/> Yet still nothing. I added the php user to the apache group also. Nothing. I uploaded the file and manually chmoded it 777 for the hell of it and then tried to write to it with the php script. Crazy, but still did not work. This boggles me so much. The csv files are all user apache the php is user foo. I played around with the users and groups a lot. Nothing... – please delete me Aug 7 '12 at 0:50

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