Why is the root directory on a web server put by default in “/var/www”

directory-structure

Tuxfiles says the following about the Linux directory structure:

/var:

This directory contains variable data that changes constantly when the system is running.

FHS on /var says the following:

/var contains variable data files. This includes spool directories and files, administrative and logging data, and transient and temporary files.

They then go on to say that things like logs, mail and the spooler are put in that folder.

Traditionally A stock installation of Apache or Nginx or Arch on Ubuntu Linux will place the directory at /var/www/.

It doesn't seem to me like the ideal place to put a directory with files or otherwise content that is supposed to be almost permanent.

Why is it so often put into /var?

More subjectively, is this where it should ideally go, according to the directory structure?

Best Answer

Usage of /var/www is confusing only at first sight.

According to the FHS, web server data should go to /srv. That is the main rule.

However, it also says that deciding about the structure of /srv is the sole responsibility of the local administrator! Therefore packages must not put anything into /srv, and the default document root must not be /srv, because the (apache) package does not know what is in /srv and below it. Maybe a subversion repository with clear text password and other things as well. So there must be a default outside of /srv. That default become /var/www.

/var/www is mostly a placeholder. Packages use /usr/share for static HTML content, or /var/lib for dynamic variable content. Many people mistakenly thought that they should then put HTML into /var/www. That is a problem, because packages occasionally use that too. So recently they invented /var/www/html for packages. Hopefully people will not start to use that because then again they have to invent a new directory... and so on.

Summary: you should use /srv and configure your Apache virtual hosts accordingly.

Related Question