views:

522

answers:

3

Are there any best-practices for how to layout your webroot on a server?

For instance, I currently have a site with this structure:

/var/www/current/html (public dir for most recent revision)
/var/www/dev/html (public dir for dev version)
/home/user/www/html (for users public sandbox)

How does everyone else layout their www file structure?

A: 

I think that is the most typical way of doing it. I use a lot of sub domains and stuff so I tend to do stuff like:

/home/user/www/sub1.domain.com/
/home/user/www/sub2.domain.com/
Peter D
+1  A: 

I don't know any best practice. Keeping it in /var is quite a good idea. The layout looks ok and is changeable any time you want. The structure below that is resolved via URLs is much harder because that is public and hard to change afterwards.

Norbert Hartl
[LFS](http://www.pathname.com/fhs/pub/fhs-2.3.html#SRVDATAFORSERVICESPROVIDEDBYSYSTEM) says site-specific data which is served by the system should go in `/srv`
Zash
A: 

I use this:

/srv/#{protocol}/#{host.split('.').reverse.join('/')}/%/

So for example http://www.example.net/index.html becomes

/srv/http/net/example/www/%/index.html

It closely follows the tree structure of DNS, follows Filesystem Hierarchy Standard, and makes it easy to delegate control in a similar way, eg by symlinking a users point in DNS to their ~/web or similar. Then the user can easily create sub domains by mkdir -p web/sub1/%

Zash
Seems like a decent structure, but what's with the '%' sign?
snemarch
The point of `%` is that it's invalid in hostnames (at least I hope so), so it works as a separator between the DNS- and path part of the tree. Something with a `_` or uppercase would work too. Also, in my Lighttpd config it is `evhost.path-pattern = "/srv/http/%1/%2/%3/%4/%5/%6/%%/"`.
Zash