Where to put the web pages in /var/www/ or /var/www/html/ in apache?

I doubt where to place different web pages if /var/www/ or /var/www/html/ in apache?


History. This question is a very old one; commonly asked at the beginning of a way of administering a servers - when, naturally, you need some rules and like to work lege artis. [DigitalOcean], [Quora]

Answer. Unfortunately, there is no rule of thumb; the two presented examples are the most common. In general, it is an internal policy and preference.

Explaination. Taking SELinux policies to the account, we can say, that

/var/www/html

could be a preferred way to put your application code. Unfortunately to that, one of the most common exercises is to add another directory to httpd label.

Of course, it might be confusing to put php application code to html directory.


Personally, me and my engineers tend to put virtual host configuration at /var/www/<vhost>


The correct place to put the site depends on the configuration if the web server. You need to find what the root of the server (for the virtual host if hosting multiple sites) is. This is specified with DocumentRoot - so go to the Apache config files (normally in /etc/Apache or /etc/apache2 or /etc/httpd and look for that directive.

/var/www/html is the typical/default location.

You should keep in the back if your mind that it is possible to override locations with "alias" directives - although these are typically used to graft programs web interfaces into a path and have a subdirectory associated with them.