PHP Page Fails with Warning: include_once ...

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.
andrew sangsteritAsked:
Who is Participating?
 
andrew sangsterConnect With a Mentor itAuthor Commented:
Hey Guys thanks for reaching out. it was the fact that the DocumentRoot could not be changed by the httpd.conf file. had nothing to do with the code. The virtual host had the correct document root but because our DNS had not been changed to point at the new host yet the temp URL would not work properly. Ended up changing the DocumentRoot for the entire VPS via Console and it now works with the temp URL and will when DNS changes to point to it as well. appreciate all the feedback. thanks again
0
 
Loganathan NatarajanConnect With a Mentor LAMP DeveloperCommented:
Your document root is incorrect that's why it shows failed to open.   /home/grfn/public_html/index.php  is not "/home/USER/public_html"

Instead of "$_SERVER['DOCUMENT_ROOT']"  , just hard code the path to include?
0
 
RedLondonCommented:
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');
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Dave BaldwinFixer of ProblemsCommented:
'/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.
0
 
Loganathan NatarajanLAMP DeveloperCommented:
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

0
 
Ray PaseurCommented:
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
 
andrew sangsteritAuthor 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
0
 
andrew sangsteritAuthor 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.
0
 
Ray PaseurCommented:
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

0
 
andrew sangsteritAuthor 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?
0
 
Ray PaseurCommented:
it doesn't work…
How do you know it doesn't work?  What is the symptom?
0
 
RedLondonCommented:
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.
0
 
Ray PaseurCommented:
@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!
0
 
andrew sangsteritAuthor Commented:
This fixed it correctly.
0
All Courses

From novice to tech pro — start learning today.