Reputation: 778
I have 3 files: database.php, intialize.php and config.php. The 3 files are located under a folder named:
usr/loca/nginx/html/phpcode/php/999_projects/test/include/
database.php
<?php
echo "before";
require_once('initialize.php');
echo "after";
echo LIB_PATH;
?>
initialize.php
<?php
// DIRECTORY_SEPARATOR is a PHP pre-defined constant
// (\ for Windows, / for Unix)
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null :
define('SITE_ROOT', $_SERVER["DOCUMENT_ROOT"].DS.'phpcode'.DS.'php'.DS.'999_projects'.DS.'test');
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');
// load config file first
require_once(LIB_PATH.DS.'config.php');
?>
config.php
<?php
// Database Constants
defined('MYSQL_DSN') ? null : define("MYSQL_DSN", "mysql:host=localhost;dbname=talkback");
defined('DB_USER') ? null : define("DB_USER", "user");
defined('DB_PASS') ? null : define("DB_PASS", "pass");
?>
Once I run database.php, I get the following:
Warning: require_once(/usr/local/nginx/html/phpcode/php/999_projects/test/includes/config.php): failed to open stream: No such file or directory in /usr/local/nginx/html/phpcode/php/999_projects/test/include/initialize.php on line 16
AND
Fatal error: require_once(): Failed opening required '/usr/local/nginx/html/phpcode/php/999_projects/talkback/includes/config.php' (include_path='.:/usr/share/php:/usr/share/pear') in /usr/local/nginx/html/phpcode/php/999_projects/talkback/include/initialize.php on line 16
The 3 files have the proper permissions and also the web server has permission to access these files.
I have tried for the past couple of hours (!) to fix it, however, I can`t find what am I missing.
Can someone please assist?
Thanks,
Qwerty
Upvotes: 0
Views: 2334
Reputation: 817
Well the locations you said don't match the location in the errors.
You said they were all located under:
/usr/loca/nginx/html/phpcode/php/999_projects/test/include/
but the errors say:
/usr/local/nginx/html/phpcode/php/999_projects/talkback/include/
one says 'talkback', one says 'test'. And one also says 'include', while the other says 'includes' But, if you positive they're under the same folder, and or those are the correct locations, more than likely the web-server does not have read access to that file.
You can check if the file path is right but going into a terminal, and typing:
cat /usr/local/nginx/html/phpcode/php/999_projects/talkback/includes/config.php
if that works then the path is right, and it will be a permissions issue, which you can check using ls -l, and changing with the chmod command (usually chmod 755 works fine).
Upvotes: 0
Reputation: 712
I think it is because you have written this:
define('LIB_PATH', SITE_ROOT.DS.'includes');
... whereas in fact you meant to write this, without an 's':
define('LIB_PATH', SITE_ROOT.DS.'include');
I'm inferring this from the last bit of each of those errors - it seems the file from which these other two are being included lives in the 'include' rather than the 'includes' directory?
/usr/local/nginx/html/phpcode/php/999_projects/talkback/include/initialize.php on line 16
Upvotes: 1