PHP 5: Mass Virtual Hosting points $_SERVER[‘DOCUMENT_ROOT’] to wrong folder

When I set up mass virtual hosting for my servers, it seems PHP won’t get the right $_SERVER[‘DOCUMENT_ROOT’]

Here’s the solution I found:

1.Edit your php.ini (the file location depends onĀ  how you have PHP setup)

2. Edit this section

; Automatically add files before PHP document.
; http://php.net/auto-prepend-file
auto_prepend_file = /home/httpd/prepend.php

3. Create the prepend file:

<?php
$_SERVER['DOCUMENT_ROOT'] = str_ireplace($_SERVER['SCRIPT_NAME'], '', $_SERVER['SCRIPT_FILENAME']);

4. Restart your httpd server. I have done this for both Apache 2 and NGINX. (It probably doesn’t matter as it’s a PHP issue)

Tagged , , , . Bookmark the permalink.

Leave a Reply