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

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
chmod g+s ~/public_html/
chown www-data:websitename ~/public_html/

Then, I add the 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.

share|improve this question

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.

share|improve this answer
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 '11 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. – ThatGraemeGuy Dec 12 '11 at 10:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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