Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

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.

share|improve this answer
1  
Your first point is incorrect, upgrading doesn't blow away /var! –  Jorge Castro Nov 20 '12 at 20:43
    
@JorgeCastro - Care to explain ^^. I have done it and every time, everything in /var gets deleted but since I KNOW you know more hehe then please correct me obiwan (robot). –  Luis Alvarado Nov 20 '12 at 21:15
    
I should read your second point before. Now I lost all my site upgrading Ubuntu :'( –  Lucio Jun 14 '13 at 22:06

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.

share|improve this answer

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.

share|improve this answer
    
can comment on own answer I think this would be better explained in ImaginaryRobots question above. –  Wes Nov 20 '12 at 20:36

Your Answer

 
discard

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.