0

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

Qwerty
  • 748
  • 1
  • 9
  • 25
  • One often runs into this error, and to quickly troubleshoot it, follow these steps : stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 15:11
  • Possible duplicate of [Php - Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Sep 11 '16 at 09:17

2 Answers2

1

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
d0ug7a5
  • 692
  • 4
  • 7
  • Yes, Yes, Yes!!! This means I need to take a break now If did not catch it should be "include" instead of "includes". So next time, if I no such file or directory, php is not wrong. it`s the coder who specified wrong path!!! – Qwerty Aug 19 '15 at 16:31
  • I have started a troubleshooting checklist for this frequent error here : stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 15:12
0

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

Kenyon
  • 807
  • 1
  • 12
  • 24
  • Hi, the errors points to "test". The problem was in the path location I specified. Thanks anyway. – Qwerty Aug 19 '15 at 16:30