Ubuntu – ‘/’var/www/’ vs ‘/home/$USER/public_html’


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.

Best Answer

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.

Related Question