We help IT Professionals succeed at work.

PHP Page Fails with Warning: include_once ...

463 Views
Last Modified: 2014-08-16
I have just migrated from cpanel shared host to another provider VPS. I have read all over the internet possible fixes to my issue but can't find an answer.

My page gives error
/usr/local/apache/htdocs/common/leftside.php): failed to open stream: No such file or directory in /home/grfn/public_html/index.php on line 63

here is the top part of my index.php file
require_once($_SERVER['DOCUMENT_ROOT'].'/application/config/configuration.php');
require_once(PATH_MODULES.'/NewsArticle.php');
require_once(PATH_MODULES.'/Poll.php');

etc etc…

Every time the page reaches a
require_once($_SERVER['DOCUMENT_ROOT']

it will fail.
Warning: include_once(): Failed opening '/usr/local/apache/htdocs/common/rightside.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/grfn/public_html/index.php on line 130


My hosting provider admins offered no real help. and i am lost. i am not a programmer by any means. i have checked the document root and it is correct (i believe)

documentroot: /home/USER/public_html

also i am running the suEXEC php handler.

any ideas i need this up for monday and have been trying for what seems like ever now to no avail. any help is appreciated.
Comment
Watch Question

Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
The error Failed opening '/usr/local/apache/htdocs/common/rightside.php' implies that $_SERVER['DOCUMENT_ROOT'] is not returning the /home/grfn/public_html/ value that you expect

Where is the /application/config/configuration.php file? If it is at /home/grfn/public_html/application/config/configuration.php, what if you replace require_once($_SERVER['DOCUMENT_ROOT'].'/application/config/configuration.php'); with require_once('/application/config/configuration.php');
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
'/usr/local/apache/htdocs/common/rightside.php' and '/home/grfn/public_html/index.php' are on different paths.  On shared hosting, you would not have access to '/usr/local/....'.   I have never needed to use $_SERVER['DOCUMENT_ROOT'] on any web site.  It is normally the same as '/'.  And on one hosting company it starts out as "/var/chroot/..." which means it is generally unusable, they have me "chroot'd" to my own web directories.
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
if your DOC ROOT is not updated in php.ini , you can use this " /home/USER/public_html"

$new_path = " /home/USER/public_html";
require_once($new_path.'/application/config/configuration.php');
require_once(PATH_MODULES.'/NewsArticle.php');
require_once(PATH_MODULES.'/Poll.php');

Open in new window

Most Valuable Expert 2011
Author of the Year 2014

Commented:
DOCUMENT_ROOT is one of those things that is an installation-dependent variable.  If you're not a programmer, it sounds like you need to hire a programmer!  If you want to explore the file path issues yourself, start by learning about getcwd() and var_dump().  These functions will help you get a foundation in what your server file system looks like to PHP.  If you're new to PHP and want to learn more, this article may help.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Author

Commented:
Hey everyone. Thanks for the replies I'll take a look and try these shortly. One quick question for you all Why is my document root wrong when my httpd.conf virtual directory has been updated to reflect the correct location maybe I don't understand but why would it call the wrong directory when the root seems ok? And what would be different between my old shared hosting and this new vps? I would think that the code wouldn't have to change as I thought $server was a variable that calls on whatever the servers document root is. It's a Cpanel account and it's a vps so I do have root access

Author

Commented:
are you suggesting i add this instead
$new_path = " /home/USER/public_html";
require_once($new_path.'/application/config/configuration.php');
require_once(PATH_MODULES.'/NewsArticle.php');
require_once(PATH_MODULES.'/Poll.php');

its always failing where the $SERVER[DOCUMENT_ROOT] is declared. I have a novice programmer working for me and he isn't able to figure this out and I am the network admin (small business) so i am stumped why it is calling wrong or different directories. can i entirely get rid of the document root request and use something else that will not matter if i change servers etc in the future?.. it seems like its calling its own index.php file too which is in the public html folder and yes the config.php is in the public one too which i would like to move out once i get this fixed. to me the site was terribly programmed.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Why is my document root wrong...
I'm not sure it is, but we can't really see all of the things you can see with a "hands-on" grip on the server.

I think if you use getcwd() you will learn a lot.  Try installing this script, shown here in its entirety, in the web root and running it.  Then put it into one of the subdirectories and try it again.  You should be able to see a pattern in the outputs.

<?php
error_reporting(E_ALL);
var_dump( getcwd() );

Open in new window

Author

Commented:
Hi Ray,

i am using a temp URL and when i navigate to that script it seems to fail..

IPADDRESS/~1234

we haven't moved our DNS over yet as we are still doing testing.

then i execute

IPADDRESS/~1234/testscript.php

it doesn't work…

any ideas?
Most Valuable Expert 2011
Author of the Year 2014

Commented:
it doesn't work…
How do you know it doesn't work?  What is the symptom?
Perhaps because the ?> closing was missing?

If this was urgent yesterday to get working by tomorrow, I'm guessing itadminbingo has fixed it and forgotten to come back, going by the 24hr silence.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
@RedLondon: The close PHP tag is required only if there are non-php statements (such as HTML) following the PHP script.  Otherwise, It usually causes more trouble than it's worth.  My recommendation is to omit it if possible.  The PHP parser knows when it is finished without us having to tell it!
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
This fixed it correctly.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.