I'm trying to set up a site of which I was not the original owner, on a new server - In Apache2, the document root has been set to /var/www/html, which is where the index.php that I want to be the default 'homepage' is located.
There are a number of files in other directories in www. For an example, /common/cachelite/Lite.php can also be found in /var/www.
The php in index.php references this using require_once, like below:
error_reporting(E_ALL);
ini_set('Display_errors','On');
require_once('../common/cachelite/Lite.php');
But throws the following error, which I have taken from my Apache2 error.log:
PHP Fatal error: require_once(): Failed opening required '../common/cachelite/Lite.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/index.php on line 4
The file itself is definitely there, so can anybody shed some light on this issue for me? What's going on?
I have run in to this problem a few times and always fix it like so.
$file = dirname(dirname(__file__));
require_once($file ."/common/cachelite/Lite.php");
To narrow it down further.
try this if doing it on the web server and not command line add <pre></pre> tags.
echo __file__ . "
";
echo dirname(__file__). "
";
echo dirname(dirname(__file__)). "
";
My next thought is, file permissions or misspelled words.
you can change your code to something like
require_once($_SERVER['DOCUMENT_ROOT'].'/common/cachelite/Lite.php');
or you can also follow this way:
require_once(dirname(__FILE__).'/common/cachelite/Lite.php');
Check the permissions on the files that you are trying to require/include. If they can't be read by the accessing/web user then that would explain the error that you are encountering.