apachemod-rewritemod-vhost-alias

How to Override DocumentRoot on Per Request Basis using VirtualDocumentRoot


So people complained about how PHP Scripts using DOCUMENT_ROOT break when Apache is being run with VirtualDocumentRoot and mod_vhost_alias since DOCUMENT_ROOT doesn't get set properly. Apache evidentally fixed this sometime ago and the brief notes are here: http://svn.apache.org/viewvc?view=revision&revision=1132494

Sadly, there isn't enough detail explaining how to actually override the DocumentRoot on a per-request basis. I'm guessing it must be done with mod_rewrite somehow but I'm not certain. Does anyone know how to do this?


Solution

  • Well, evidentally, I wasn't quite asking the right question. Here's some information I got directly from Stephan on the Apache2 Bugzilla list:

    Stephan said:

    The bug report was about VirtualDocumentRoot and this now sets DOCUMENT_ROOT correctly. Therefore the issue is resolved.

    And I pushed back to clarify:

    Maybe I missed something but I'm pretty certain I tested $_SERVER['DOCUMENT_ROOT'] in php and it wasn't matching the value set by VirtualDocumentRoot. You're saying it should match now?

    And he replied:

    Yes, in 2.4.x. It is very unlikely that the fix will ever be ported to 2.2.x because it requires infrastructure that is only present in 2.4.

    So I ran apache2 -v and discovered I'm not running 2.4.x. Apache2 -v shows this:

    Server version: Apache/2.2.16 (Debian)
    Server built:   Nov 30 2012 08:33:45
    

    And if you notice the Server was built at the end of November this year when I used aptitude -install apache2. I don't know if apt-get would have pulled apache 2.4 instead. This is very lame. 2.4.3 stable was released in August. I don't know why aptitude pulled 2.2 but this really created a nightmare for me.

    So in reality, the question I asked was moot. Everything should have worked fine, except that aptitude installed an outdated apache2 and I didn't realize what was going on. There is no bug anymore.