I got the following error when a file is included.
Warning: require(home2/myusername/public_html/inc/config.php)
[function.require]: failed to open stream: No such file or directory in
/home2/myusername/public_html/inc/bootstrap.php on line 32
Fatal error: require() [function.require]: Failed opening required
'home2/myusername/public_html/inc/config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in
/home2/myusername/public_html/inc/bootstrap.php on line 32
It is working fine in my localhost running on Windows PC. But I got that error when I uploaded the files on my shared hosting server which is CentOS.
home2/myusername/public_html/index.php
includes /inc/bootstrap.php
which is then trying to include /inc/config.php
. The file config.php
does exist on the server. home2/myusername/public_html/
is returned by the function getcwd()
.
The below is the first few lines of codes in bootstrap.php which issues the error.
define('APP_DIR', 'app');
if( !defined('APP_ROOT') ){
$APP_ROOT = trim(getcwd(), '/').'/';
if(isset($_GET['bootstrap'])) $APP_ROOT .= APP_DIR . '/';
define('APP_ROOT', $APP_ROOT);
}
if( !defined('ROOT') ){
$ROOT = str_replace(APP_DIR, '', trim(APP_ROOT, '/'));
if( strrpos($ROOT, '/') != strlen($ROOT)-1 ) $ROOT .= '/';
define('ROOT', $ROOT);
}
# path to inc/ folder
define('INC', ROOT.'inc/');
# System configuration variables
require INC . 'config.php';
I have also a URL Rewrite in /public_html/.htaccess
.
RewriteRule ^index.php$ index.php?bootstrap [L]
So, when I browse example.com/index.php
, it rewrites to example.com/index.php?bootstrap
. It is the situation I got the error.
Here is my directory structure:
/public_html/
|__ inc
| |__ bootstrap.php
| |__ config.php
|__ .htaccess
|__ index.php <--- I'm browsing this
I think the problem would be related to the absolute path file include. The relative path file include require 'inc/bootstrap.php
in index.php is okay.