Super User is a question and answer site for computer enthusiasts and power users. 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 am running a cakephp webapp on Linode LAMP. I am finding that my temp files are created with root:root ownership. But the webapp is running with Apache's permissions (www-data). This causes warnings any time there is a new file created because it is not writable for user www-data.

How do I change the default ownership to www-data on any new files created in the temp folder?

Thanks for your help!

share|improve this question

migrated from stackoverflow.com Jun 16 '12 at 21:04

This question came from our site for professional and enthusiast programmers.

To assign group ownership by www-data regardless of the uid/gid of the process that creates the file, you need to set the setgid bit on the directory.

    sudo chown :www-data <dir>
    sudo chmod g+s <dir>

Note that you must also make the directory writable by whatever process will create the files. If that's anyone but root, you may also need chmod o+rwx to get things working properly.

share|improve this answer
    
What about sub-directories? – Matteo Dec 23 '14 at 21:07
    
Appending the -R flag to chown and chmod makes that command recursive. So the commands below will assign default group ownership to <dir> as well as all subdirectories of <dir>: sudo chown -R :www-data <dir> and sudo chmod -R g+s <dir> – Josh Wieder Aug 2 '15 at 14:04

You must log in to answer this question.