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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With