Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I first started programming for the web and I wanted to create a new project I was always taught to create a directory in /var/www/. However in a lot of tutorials I read people tend to create a directory in /home/username/.

I don't like the idea of putting it in /home/username/.

Is there a correct place or if not what are the advantages/disadvantages of placing it in certain areas on the file system?

share|improve this question
    
That's preference ("best" implies that, maybe you should change this to be most secure, etc.) for development mostly. If you are serving them from there too, then you'd probably want something secluded to keep some sort of distance between your personal files and web-share stuff. But there are a million configurations. I stick with /var/www and usually have that on another drive (just preference). –  nerdwaller Aug 22 '13 at 13:40
    
There is no "best" directory. Its entirely your perference because the phyiscal location of the files does not matter. –  Ramhound Aug 22 '13 at 13:42
add comment

1 Answer 1

up vote 6 down vote accepted

There is no "best" directory. And while people might argue that this question is subjective, or that the actual placement of files does not matter—and they're right about the latter—there are standardized recommendations on where to put what in Unix-like systems.

The Filesystem Hierarchy Standard defines this and offers you the following:

  • /var – a place to put data that changes during normal operation, like logs, etc. /var/www is the default directory to place web content for Apache, but its usage is not standardized at all and just the "usual" place you'd put it because people don't change the default settings very often.

  • /srv – this directory should contain data that is served by the system. This is usually the place you want. The FHS explains:

    This main purpose of specifying this is so that users may find the location of the data files for particular service, and so that services which require a single tree for readonly data, writable data and scripts (such as cgi scripts) can be reasonably placed. Data that is only of interest to a specific user should go in that users’ home directory. (…)

    One method for structuring data under /srv is by protocol, eg. ftp, rsync, www, and cvs

    So, simply create a /srv/www directory and use this. You can create subfolders for every virtual host you might want to serve with your machine.

  • /home contains files that really should just belong to one user. Apache for example allows userdirs, so you can access a user's web files through http://example.com/~username, and they're served from the public_html directory in the user's home.

    If you use a server that is shared among multiple people, and you want to allow everybody to host their own scripts, this is where they should go. Remember to make the directories writable by the user they belong to only.

In essence /srv/www and /var/www are directories you should create subdirectories in for any web project you might want to host. You can then define different permissions on these directories to allow certain users or user groups to write to them. If you have projects for one user at a time, use /home.

share|improve this answer
3  
The http://example.com/~username usually does not point to /home/username/, but to /home/username/public_html/. –  choroba Aug 22 '13 at 13:47
    
Yeah, thanks, that should have been added for clarity. Done. –  slhck Aug 22 '13 at 13:51
add comment

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.