Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0

Tags:

laravel

After creating a fresh Laraver project using:

laravel new [project_name]

At first it ran, but after running it for the second time I got an error saying:

Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0

Fatal error: Unknown: Failed opening required 'D:[path]\server.php' (include_path='C:\xampp\php\PEAR') in Unknown on line 0

like image 979
MrTindervox Avatar asked Apr 05 '18 22:04

MrTindervox


4 Answers

That's because you are probably using Avast antivirus, The solution is simply open the Antivirus-check virus and threats, make server.php an exception and try open the localhost again, it should now work

like image 189
Kenneth Kimani Avatar answered Nov 02 '22 05:11

Kenneth Kimani


The problem was that the initial directory included server.php file and the second time around it was missing.

For me this was a weird interaction with Avast as it perceived the file as malicious. Check Avast's Virus chest to recover the file to avoid further issues.

Maybe this will save time for somebody.

like image 23
MrTindervox Avatar answered Nov 02 '22 07:11

MrTindervox


This error occurs when the server.php file is needed in the root directory of the project, if you need it you can create the file and basically this is the code that must contain.

server.php

<?php
$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}
require_once __DIR__.'/public/index.php';
like image 7
Vladimir Salguero Avatar answered Nov 02 '22 06:11

Vladimir Salguero


Seems that you have deleted the server.php file from the root of the Laravel project. You can re-create new server.php and put the PHP script as given,

<?php
    $uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
    if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
        return false;
    }
    require_once __DIR__.'/public/index.php';

or you can go to the official laravel github repo to grab the original server.php file.

like image 2
Kiran Maniya Avatar answered Nov 02 '22 06:11

Kiran Maniya