Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

This question already has an answer here:

I have files on my website which I need access to files on my server and they also need to be able to be edited by the webserver. Now with my current setup I cant seem to do that.

If the owner/group is imran:imran then I have full access to that file but my webserver cant seem to open/edit those file. Now I was told that I need to match the files owner/group with the ones the webserver uses, I had a look at files that the webserver created and they were nobody:nobody. So I changed my whole public_html owner/group to nobody:nobody because I simply had too many files in the folder which needed to be edited by the webserver and would take too long to change owner one by one. The webserver was able to edit it just fine after changing the owner but then I realized something.. now I cant even view the public_html folder.

Does anyone know whats the correct way to set the owners so that I have access as well as the webserver?

(This is on a WHM/cPanel powered server)

share|improve this question

marked as duplicate by HopelessN00b, Ward, HBruijn Feb 22 at 6:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

The following commands:

chown imran:nobody public_html
chmod 0775 public_html

chown imran:nobody -R public_html/* 
find public_html/ -type f -exec chmod 0664 '{}' \;
find public_html/ -type d -exec chmod 2775 '{}' \;

# In your .bash_profile / .bashrc set:
umask 002

That should take care of your troubles. It gives the nobody group permission to write to the public_html directory and subfolders, but 'the world' is not allowed to write to those files (eg chmod 777). You, as the owner, also have full permissions over those files. Setting the setgid bit on the directories makes sure the permissions stay this way and the umask modification means you'll create files with a different set of default permissions.

Sometimes, the nobody user is not part of its own group, so to fix that use

gpasswd -a nobody nobody

Make sure you add the +x bit on anything you need to be executed by the webserver, CGI scripts etc.

share|improve this answer
The user:group in chown should be after -R – Gonzalo Nov 19 '09 at 3:56
He should probably consider adding the setgid bit for directories and set his umask. This will make new files automatically get the correct group, and permissions. – Zoredache Nov 19 '09 at 7:59
Ok well I tried the above^^ but it didnt work :-( – Imran Nov 25 '09 at 23:44