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

saidi's avatar
Level 2

Failed to require files in php script.

Hello, i am a beginner php dev and and currently following the beginner series here on laracast. I ran in to this problem where i try to require files in another directory different from that of the file am calling from. The sample code and the server response are as shown below.


<?php

require('core/config.php');

$messages_q = "SELECT * FROM communications";
if ($result_message = $conn->prepare($messages_q)) {
    $result_message->execute();
    $messages_arr = $result_message->fetchAll();
}

require 'views/index.view.php';

resoponse

Warning: require(core/config.php): failed to open stream: No such file or directory in C:\xampp\htdocs\HogwartsStudentPortal\controllers\index.php on line 3

Fatal error: require(): Failed opening required 'core/config.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\HogwartsStudentPortal\controllers\index.php on line 3

Any help will be highly appreciated, Thank you.

0 likes
2 replies
ismaile's avatar
ismaile
Best Answer
Level 30

In index.php, you use:

require('core/config.php');

So, in the same location as index.php, you should have a core folder. Both index.php and the core folder should be in the same controllers folder to make your code work. However, maybe it makes more sense to have the core folder directly in HogwartsStudentPortal. In this case, you could use:

require('../core/config.php');

to first get to the parent directory with ..

1 like

Please or to participate in this conversation.