Link to home
Start Free TrialLog in
Avatar of andrew sangster
andrew sangster

asked on

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.
SOLUTION
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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');
'/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.
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

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
Avatar of andrew sangster
andrew sangster

ASKER

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
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.
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

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?
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.
@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!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This fixed it correctly.