Unable to include the file and receive the message "could not open the stream: there is no such file or directory"

I got the following error when the 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 works fine in my local host running on a Windows PC. But I got this error when I uploaded files on my shared hosting server, which is CentOS.

home2/myusername/public_html/index.phpturns on /inc/bootstrap.php, which then tries to turn on /inc/config.php. The file config.phpexists on the server. home2/myusername/public_html/returned by function getcwd().

Below are the first few lines of code in bootstrap.php that cause 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 a Rewrite's URL /public_html/.htaccess.

RewriteRule ^index.php$ index.php?bootstrap [L]

So when I browse example.com/index.php, it texted to example.com/index.php?bootstrap. This I got an error.

Here is my directory structure:

/public_html/
    |__ inc
    |   |__ bootstrap.php
    |   |__ config.php
    |__ .htaccess
    |__ index.php <--- I'm browsing this    

, . require 'inc/bootstrap.php index.php .

+3
2

:

/home2/myusername/public_html/index.php

bootstrap.php :

/home2/myusername/public_html/inc/bootstrap.php

:

include_once $_SERVER['DOCUMENT_ROOT']."/inc/bootstrap.php";

$_ SERVER ['DOCUMENT_ROOT'] /home2/myusername/public_html

+5

, . . config.php bootstrap.php, .

, .

/inc/config.php config.php.

.

EDIT:

'/'

Failed opening required 'home2/myusername/public_html/inc/config.php' 

'/home2/myusername/public_html/inc/config.php'
0

All Articles