php - VirtualDocumentRoot works well but does not make any change to $_SERVER["DOCUMENT_ROOT"] -


I use the VirtualDocumentRoot command for Dynamic Virtual hosts in Apca, now my virtualhost is working fine, but I $ _SERVER ["DOCUMENT_ROOT"] Still the value of the first DocumentRoot definition is not the VirtualDocumentRoot value!

My "http.conf" is a short piece of file:

  Use the clock name to close DocumentRoot "/ var / www / html" & lt; VirtualHost *: 80 & gt; ServerAdmin admin @ localhost VirtualDocumentRoot "/ var / vhosts /% 0" error log "log / dynamic-vhosts-error.log" custom log "log / dynamic-vhosts-access.log" combined & lt; / VirtualHost & gt;  

When I run this php code bellow

  & lt; Php echo $ _SERVER ["DOCUMENT_ROOT"]; ? & Gt;  

I get the result as / var / www / html if I comment on this line

  #documentRoot "/ var / www / Html " 

PHP result will be

   

but I should have value of $ _SERVER [" DOCUMENT_ROOT "]:

  / var / vhosts / for example. Com.com  

Is there a solution for this?

see

I have a great for this in the related Apache bug report Found the solution: Just add the following line to your Apache configuration within the virtual documentual Virtual definition:

Php_admin_value auto_prepend_file /path/setdocroot.php

Then, referenced Create the PHP file, and set it as your content:

& lt; Php $ _SERVER ['DOCUMENT_ROOT'] = str_replace ($ _ server ['SCRIPT_NAME'], '', $ _SERVER ['SCRIPT_FILENAME']);

Now, this file has been executed in each page load, which sets DOCUMENT_ROOT correctly.


Comments