0

On my VPS, at the moment, I'm hosting multiple websites on different virtual hosts using apache2.

The creation process of each new website is as following:

adduser websitename
su websitename
mkdir ~/public_html
mkdir ~/logs
exit    
chmod g+s ~/public_html/
chown www-data:websitename ~/public_html/

Then, I add the websitename.com virutal host file to /etc/apache2/sites-available/ and run the a2ensite command and restart the apache2 process.

I have 2 questions:

  1. At the moment, www-data has no real permissions to edit the files on /public_html/ for some reason, how can I fix this?
  2. Is there anything else you would add to the process of creating the vhost?

P.S: I'm using Ubuntu 10.04 hosted on Linode.

1 Answer 1

0

This command:

chown www-data:websitename ~/public_html/

changes the owner and group for the directory, but not anything underneath it. Its not clear from your question where exactly the contents of the directory comes from, but assuming that there is something in there at the time you run the chown command, you will need to tell it to recurse the directory in order to apply those permissions to the contents of ~/public_html, and not just to the directory itself.

chown -R www-data:websitename ~/public_html/

Its also generally frowned upon to give the web server permission to write to just anything, you should consider which files it really needs to be able to write to in order to function properly and only allow it to write those specific files.

2
  • So let's say I have a wordpress installation on public_html, and I want to give access to www-data for the wp-content folder, I should run chown -R www-data:websitename ~/public_html/wp-content/ and that will allow apache to edit the files within wp-content, correct? What about when I add files to wp-content, will www-data have permissions to edit these without me running the chown command again?
    – user838437
    Dec 8, 2011 at 13:50
  • Yes that should work. When it creates files under that directory, www-data should be the owner and thus be able to edit the file/s later if needed. Dec 12, 2011 at 10:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .