Knowledgebase
Net Access > Customer Support Help Desk > Knowledgebase

How can I change the DOCUMENT_ROOT variable for PHP?

Solution If you are running into issues with the $_SERVER["DOCUMENT_ROOT"] variable showing '/var/www' when using PHP4 or PHP5 (non-ITK) and need to have it point to your correct document root for your application, here is a simple two step tutorial for changing it.


1. Create a file under your content directory called document_root.php. Add the following code to this file:

<?php
$_SERVER["DOCUMENT_ROOT"] = "/mnt/target01/123456/123456/www.domain.com/web/content";
?>


*Note: Make sure to replace the actual location with your content location. You can find this on the Features tab for the website in the Control Panel.


2. Add the following to your .htaccess file under your content directory:

php_value auto_prepend_file "/mnt/target01/123456/123456/www.domain.com/web/content/document_root.php"

This tells Apache to parse the document_root.php file before doing anything else and will cause the $_SERVER["DOCUMENT_ROOT"] to change to your content directory rather than '/var/www'. Be sure to give the full path to the file in .htaccess to avoid any complications with calls from subdirectories.

*Note: The .htaccess file will only work on our PHP environment and is usually located under the content folder. If it does not exist you will need to create it.


Your document root will now be set to your content directory rather than '/var/www'. Please note that this would only need to be done if your site resides on our legacy PHP clusters as the newer ITK clusters have the document root set to your content directory by default. You should now be able to view the _SERVER["DOCUMENT_ROOT"] variable through a PHPinfo page as your content directory.
 
Was this article helpful? yes / no
Article details
Article ID: 83
Category: Cloud Hosting
Date added: 2009-09-03 02:37:47
Views: 1215
Rating (Votes): Article rated 3.0/5.0 (6)

 
<< Go back

Powered by Help Desk Software HESK™