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

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.


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';

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.

Tags:

Laravel