-1

Getting this warning when trying to run my local PHP project (index.php):

Warning: require_once(/Controller/BulletinController.php): failed to open stream: No such file or directory in /Library/WebServer/Documents/WEBB_SERVER/6.2.1x/index.php on line 2

Fatal error: require_once(): Failed opening required '/Controller/BulletinController.php' (include_path='.:') in /Library/WebServer/Documents/WEBB_SERVER/6.2.1x/index.php on line 2

No such file or directory? This is my first 6 rows in index.php:

   <?php
   require_once ("/Controller/BulletinController.php");
   require_once ("/General/MasterPage.php");
   require_once ("./General/dbConnection.php");

   session_start();

I've tried giving BulletinController.php 777 rights (just developing locally), but no luck.

This is what my structure looks like, so everything is in place:

This is what my structure looks like

Thankful for any advice you may have.

Dolcens
  • 6,201
  • 2
  • 12
  • 12

2 Answers2

2
require_once ("/Controller/BulletinController.php");  

must be

require_once ("Controller/BulletinController.php");
Greg Kelesidis
  • 1,069
  • 14
  • 20
  • Unfortunately, this did not cut it. Thanks anyway, will keep looking for other solutions, let me know if you have any other idea. It just says: – Dolcens Nov 22 '15 at 21:40
  • Warning: require_once(/settings.php): failed to open stream: No such file or directory in /Library/WebServer/Documents/WEBB_SERVER/6.2.1x/General/dbConnection.php on line 2 Fatal error: require_once(): Failed opening required '/settings.php' (include_path='.:') in /Library/WebServer/Documents/WEBB_SERVER/6.2.1x/General/dbConnection.php on line 2 – Dolcens Nov 22 '15 at 21:40
  • I wrote this answer to show that the slash '/' at the beginning of the path is the problem. It points to the root path of the server. Now, settings.php path needs correction. When the path begins without the slash is the relative path to the file where the require statement lies. – Greg Kelesidis Nov 22 '15 at 21:51
  • There is now a troubleshooting checklist for this frequent error here : https://stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 15:36
0

I think you need the whole path:

require_once dirname(__FILE__) . "/Controller/BulletinController.php";
Teddy
  • 1
  • 1
  • Thanks for helping out! Still got an error though, now it says; Fatal error: Undefined constant '__FILE\__' in /Library/WebServer/Documents/WEBB_SERVER/6.2.1x/index.php on line 2 – Dolcens Nov 22 '15 at 21:20
  • Other variant is to use basename(__DIR__) instead of dirname(__FILE__) – Teddy Nov 22 '15 at 21:25
  • Still no luck unfortunately, will keep trying to solve the prob. Thanks alot anyway Teddy! – Dolcens Nov 22 '15 at 21:43
  • Warning: require_once(DIR/Controller/BulletinController.php): failed to open stream: No such file or directory in /Library/WebServer/Documents/WEBB_SERVER/6.2.1x/index.php on line 2 Fatal error: require_once(): Failed opening required 'DIR/Controller/BulletinController.php' (include_path='.:') in /Library/WebServer/Documents/WEBB_SERVER/6.2.1x/index.php on line 2 – Dolcens Nov 22 '15 at 21:43