Forum Moderators: coopster

Message Too Old, No Replies

Document root not pointing to the correct path

         

mr_nabo

1:20 pm on Jan 14, 2010 (gmt 0)

10+ Year Member



Hi,

But of an emergency here. I've changed the A records to point to a new webhosting package with Hostgator and my includes using the code:

<?php include($_SERVER['DOCUMENT_ROOT'] ."/includes/head.inc.php"); ?>

This is the error I'm getting

Warning: include(/usr/local/apache/htdocs/includes/head.inc.php) [function.include]: failed to open stream: No such file or directory in /home/username/public_html/index.php on line 1

Warning: include() [function.include]: Failed opening '/usr/local/apache/htdocs/includes/head.inc.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/username/public_html/index.php on line 1.......etc.

When I look at phpinfo(), it shows that the path to DOCUMENT_ROOT is '/usr/local/apache/htdocs/' whereas I'm assuming it should be '/home/username/public_html/' right?

Is this something I need my webhost to change, or can I do it myself within something like php.ini?

Thanks,

mn

TheMadScientist

7:11 pm on Jan 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you tried hard-coding the location as a 'quick-fix'?

<?php include '/home/username/public_html/'."includes/head.inc.php" ?>

rocknbil also suggests setting a constant rather than changing the location multiple times, which seems like good advice:

<?php
define("ROOT_PATH","/home/username/public_html/");
include ROOT_PATH . "includes/head.inc.php";
?>

rocknbil

10:10 pm on Jan 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When I look at phpinfo(), it shows that the path to DOCUMENT_ROOT is '/usr/local/apache/htdocs/' whereas I'm assuming it should be '/home/username/public_html/' right?

Shared hosting?

I am guessing this is one of those cases where the document root does not equal your domain root due to the way the hosting is set up. Your actual domain root is probably aliased from somewhere.

The DOCUMENT_ROOT is not a PHP variable, it is a server environment variable, so it's highly unlikely you'll be able to modify it, nor should you want to. The full server path to your actual files, as suggested, is probably the only "fix".

mr_nabo

10:48 pm on Jan 14, 2010 (gmt 0)

10+ Year Member



Hi guys,

Thanks for all your help - it ended up being an issue with the Webhost, they needed to fix it their end.

Thanks again