5

I found it very difficult to find this answer, after an hour (yes, an hour) of googling and browsing through several posts on stackexchange and several other forums... even through Apache's Documentation!

I could not for the life of me find what the difference between these two are, add to that I'm fairly inexperienced with Apache.

I came across this when looking for alternative solutions to creating a dev server for PHP and MySQL on my local machine. I was following this tutorial:

https://mallinson.ca/osx-web-development/

...which mentions "VirtualDocumentRoot" but does not specify why this is a better (is it?) choice over DocumentRoot.

Any leads or links to where I might find documentation on this would be most appreciated. Thanks!

Note: The closest I found to documentation was only on DocumentRoot http://httpd.apache.org/docs/2.4/mod/core.html#documentroot

Jay
  • 191
  • 1
  • 2
  • 9

3 Answers3

10

DocumentRoot is a standard Apache directive. Depending on the context it is used in, it sets the global document root, or the document root of a virtual host, to a fixed path.

VirtualDocumentRoot is a directive to the Apache module mod_vhost_alias. It sets the document root to a dynamic path that may contain variables which are evaluated when an actual request is handled. That way the effective document root can depend on the actual host name and port number requested, without defining separate virtual hosts for all the combinations.

Tilman Schmidt
  • 3,778
  • 10
  • 23
4

DocumentRoot can only be set to 1 value per configured VirtualHost.

VirtualDocumentRoot allows a single virtual host, that ostensibly handles traffic for lots of unrelated domains, and act as if each domain points to a unique documentroot.

covener
  • 1,665
  • 9
  • 15
1

My understanding of the difference is that DocumentRoot more like a global variable for use in the apache config file it is a single varable that declares the global root for web root.

VirtualDocumentRoot is used when you are defining Virtualhost it a nested variable inside of and cannot stand as singular variable. As the name implies it is the document root for a virtual host

So in simple terms DocumentRoot is the global root for apache config and VirtualDocumentRoot is the root for a virtual host.

Tom Goetz
  • 23
  • 5