4

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

9

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.

| improve this answer | |
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.

| improve this answer | |
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.