0

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)

1 Answers1

1

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.

Sam Halicke
  • 6,222
  • 1
  • 25
  • 35