Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jcp8089's avatar

PHP: "Failed to open stream: No such file or directory in..."

Hello, (huge) beginner PHP learner here.

For some damn reason, after having written required("./file/path"), it seems like I have "no such file or directory in" said path file.

Here's what I wrote:

require_once("./TestInc/testConfig.inc.php"); require_once("./TestInc/testPlayer.inc.php"); require_once("./TestInc/testMonsters.inc.php"); require_once("./TestInc/testLogic.inc.php");

Here's he error shown:

"jcp@MacBook Test % php TestFile.php PHP Warning: require_once(./testConfig.inc.php): Failed to open stream: No such file or directory in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php jcp@MacBook Test % php TestFile.php PHP Warning: require_once(./testConfig.inc.php): Failed to open stream: No such file or directory in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php jcp@MacBook Test % php TestFile.php PHP Warning: require_once(./testConfig.inc.php): Failed to open stream: No such file or directory in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php jcp@MacBook Test % php TestFile.php PHP Warning: require_once(./testConfig.inc.php): Failed to open stream: No such file or directory in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php jcp@Macbook Test % php TestFile.php PHP Warning: require_once(./testConfig.inc.php): Failed to open stream: No such file or directory in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php jcp@Macbook Test % php TestFile.php PHP Warning: require_once(./testConfig.inc.php): Failed to open stream: No such file or directory in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php on line 3

Warning: require_once(./testConfig.inc.php): Failed to open stream: No such file or directory in /Users/jcp/Desktop/Documents/PHP/Labs/Test/TestInc/testPlayer.inc.php on line 3 PHP Fatal error: Uncaught Error: Failed opening required './testConfig.inc.php' (include_path='.:/opt/homebrew/Cellar/php/8.1.6/share/php/pear') in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php:3 Stack trace: #0 /Users/jcp/Desktop/Documents/Test/TestFile.php(4): require_once() #1 {main} thrown in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php on line 3

Fatal error: Uncaught Error: Failed opening required './testConfig.inc.php' (include_path='.:/opt/homebrew/Cellar/php/8.1.6/share/php/pear') in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php:3 Stack trace: #0 /Users/jcp/Desktop/Documents/Test/TestFile.php(4): require_once() #1 {main} thrown in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php on line 3"

0 likes
4 replies
christian-qode's avatar

Hi @chkpk8089 , it means the file you're referring does not exists. Best thing is to follow the path /Users/jcp/Desktop.... step by step to see where the problem is. Keep in mind the path must be exactly right, and can be case-sensitive based on your system.

1 like
jcp8089's avatar

@christian-qode Hey Christian, appreciate the reply. Hmmm, that's really odd. I've checked the file pathway about a dozen times, and I see nothing wrong with it. I tried putting in the absolute path (which I copied by right-clicking on my file and copying its path) as opposed to having the relative path put in 'require_once', but that obviously did nothing. I can physically (or visually, more like) see the files in the file path written in my program when I open the folder. I'm so frustrated to have been caught up with file path issues.. Could it be some other issue that might be causing my program to think that my required file doesn't exist?

MohamedTammam's avatar

Use __DIR__ to reference the current file directory

require_once(__DIR__ . "/TestInc/testConfig.inc.php");
1 like
jcp8089's avatar

@MohamedTammam Thanks for your response! Unfortunately, that did not work.. This is the error message I received:

PHP Warning: require_once(./testConfig.inc.php): Failed to open stream: No such file or directory in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php on line 3

Warning: require_once(./testConfig.inc.php): Failed to open stream: No such file or directory in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php on line 3 PHP Fatal error: Uncaught Error: Failed opening required './testConfig.inc.php' (include_path='.:/opt/homebrew/Cellar/php/8.1.6/share/php/pear') in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php:3 Stack trace: #0 /Users/jcp/Desktop/Documents/Test/TestFile.php(4): require_once() #1 {main} thrown in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php on line 3

Fatal error: Uncaught Error: Failed opening required './testConfig.inc.php' (include_path='.:/opt/homebrew/Cellar/php/8.1.6/share/php/pear') in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php:3 Stack trace: #0 /Users/jcp/Desktop/Documents/Test/TestFile.php(4): require_once() #1 {main} thrown in /Users/jcp/Desktop/Documents/Test/TestInc/testPlayer.inc.php on line 3

Please or to participate in this conversation.