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/
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/
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.
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/
.
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
.)
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:
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).