0

Where should I put my site root directory "my_site"? Any best practice?

/var/www/my_site/
/var/local/sites/my_site/
/usr/share/wwww/my_site/
/usr/local/my_site/
/opt/my_site/
/srv/my_site/
1
  • Whist there should only be one 'best practice' in reality everyone has their own. Use the FHS.
    – user9517
    Oct 12, 2014 at 5:41

4 Answers 4

2

There is no best place to put it. It's a matter of preference.

Putting it under /var/www is fairly common. I use /var/www/sites/<vhost>.

Putting it under the others isn't common.

I personally would never put it under /usr/share.

Just make sure you put it in the same place consistently. If you end up managing dozens or hundreds of web servers and the DocumentRoot varies from server to server you're going to have a bad time.

2

Practice varies, and I don't think that there is any general consensus or that it matters enough for there to really be a "best".

Distributions tend to default to /var/www, which makes sense if you interpret /var as "writable system data". Many people just follow this default and put their own stuff there.

Other people (and, this was often the distro default > 15 years ago) use /home/www or similar, right next to any user home directories. I think generally this is considered not best practice, as policies for users and server application data are generally very different, and there may be a user associated with the service which shouldn't have write access to the files, and overall it just seems like a messy use of the namespace.

/usr/share is also generally not a good idea, because on modern distros /usr (with the exception of /usr/local) is territory which should be under control of the distribution's package manager, and not written to otherwise.

On the positive side: the Filesystem Hierarchy Standard specifies /srv as basically specifically for this purpose:

/srv contains site-specific data which is served by this system.

and

[...] /srv should always exist on FHS compliant systems and should be used as the default location for such data.

So, if you really want a standard to follow, there is one. Personally, I like this, and have found that it makes backup policy much easier. (Most of /var is transient variable data that doesn't need to be retained for long if at all, at least as long as you're following the practice of putting the actual "business" data in /srv.)

1

There is no hard coded preference set for putting it under any particular directory.

I prefer /home/acountname/public_html to keep all site related data if I am hosting multiple website on single server since I put account name as business or user or client for which I am hosting the website .

Most popular document root are /var/www/html/ and /var/www/sites/if you are hosting only one website.

You can put anywhere as per your need. But off course no one will suggest putting it under /usr/share/.

0
0

There isn't a "correct" place, but is not a bad idea trying to respect the habits of distributions. According to the FHS and other sources, the data owned and managed by programs belongs to 6 different folders:

  • /usr/share: non-modifiable data thought to be independent of the architecture (of course, for system administrators there no exists non-modifiable data).
  • /etc: non-modifiable configuration data (again, system administrators have always the last word).
  • /run: variable data used by processes during their whole lifetime (but non-persistent between reboots).
  • /tmp: variable data used during short periods of time (non-persistent between reboots).
  • /var: other auxiliar/optional data (persistent data, data which can be modified by the user, and in general, other data not suitable for other folders). Common subfolders:
    • www: websites
    • mail: mail boxes
    • tmp: same as /tmp, but for temporary data which need survive between reboots.
    • spool: data waiting for be delivered to or used by other programs/hosts.
    • lock: locked files.
  • /srv: Same as /var, but thought for services instead of other programs.

According to these descriptions, websites should go to /srv/www, but debian system don't use it. They used /var instead (/var/www, /var/mail and so on).

Not the answer you're looking for? Browse other questions tagged .