9

I recently started using Ubuntu as a LAMP server. I've come across plenty of tutorials that say to place the files at '/var/www/' and I've also seen others that put them in '/home/$USER/public_html/'.

During my testing and figuring stuff out, I was successfully able to view a test site URL from each location.

Is one better than the other? I thought that maybe it was just preference. But the more I think about it, the more I want to keep all my work in my Home folder.

3 Answers3

4

The differences are the following:

  1. If you leave it in /var/www you will have some permission problems that you will have to deal with. In your home folder, you are in charge since all files in it have your ownership by default.

  2. Some users have the /home folder in another partition which means a +1 if you happen to format the root partition and leave the home partition alone for an upgrade.

  3. It saves you from adding a user to /var/www or having to change permissions for it if you just put it in your home folder. For example instead of /var/www it would be /home/USER/www.

  4. If you need to share via Samba the files, it is MUCH easier to do it in /home than outside of it.

There are more reasons but this are the ones at the top of my mind right now.

Luis Alvarado
  • 216,643
3

In general, it will depend on what sort of development are you doing. If it is purely personal or for learning/testing purposes, then having it in ~/public_html is fine - there is no real difference as far as the webserver is concerned, and you won't run into any permission issues that way. But if your development will need to be deployed to other servers where things might not match up with your dev box, testing it in /var/www is a very good idea.

I generally do my web development in a bazaar branch under ~/local/src/ , then I use bzr push to copy completed code into a folder under /var/www for testing. Once it's reasonably tested there, I can use bzr-upload to push the code to my actual production server. This ensures that anything that gets deployed is checked in and tested, keeps /var/www clean, and keeps all of the working source code in my homedir.

1

In your home folder is probably best if you and only you are changing the contents. /var/www/public_html is more standard and works if the user dir directive is turned off.

Rule of thumb: if multiple people will be changing the content it's better to put it into /var/www/public_html and make that folder group writeable allowing all users who publish content to write there.

Otherwise, either location is fine for the reasons given in the other answers.

brasofilo
  • 192
Wes
  • 238