Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using VirtualDocumentRoot in my Virtual host configuration.

My VirtualDocumentRoot is set to /var/www/%1/ and if I create a folder say test, it is working as expected. The problem is, when I am using $_SERVER["DOCUMENT_ROOT"] in my php files it is retuning /var/www. Is it possible to have php return the same path for $_SERVER["DOCUMENT_ROOT"] as configured in VirtualDocumentRoot.

share|improve this question

If you can edit your PHP, you could calculate the correct DOCUMENT_ROOT and update the variable on the bootstrap. Here is an example:

share|improve this answer

Following the advice in the link in @Thomas' answer, this is how I dealt with this;

In my dynamic virtual host directive in httpd.conf, I added this php prepend;

php_admin_value auto_prepend_file /var/www/html/

Then in the root of my uat directory, I saved a little file that is prepended to all requests met by the dynamic virtual host entry (not all hosts on this server are dynamic, and I don't want to mess with the other ones). In it, I put this;

$path = explode("/",str_replace($_SERVER['DOCUMENT_ROOT'],"",$_SERVER['SCRIPT_FILENAME']));
$_SERVER['DOCUMENT_ROOT'] .= "/" . $path[1] . "/" . $path[2];

This works for me because my VirtualDocumentRoot is two levels beneath my httpd document root. If yours is any deeper, you will need to adjust the indices of the $path array.

Hope this helps others with the same issue...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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