Laravel 警告:未知:无法打开流:第 0 行未知中没有此类文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49682640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
提问by MrTindervox
After creating a fresh Laraver project using:
使用以下命令创建新的 Laraver 项目后:
laravel new [project_name]
laravel 新 [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
警告:未知:无法打开流:第 0 行的未知中没有此类文件或目录
致命错误:未知:在第 0 行的未知中打开所需的 'D:[path]\server.php' (include_path='C:\xampp\php\PEAR') 失败
回答by MrTindervox
The problem was that the initial directory included server.php file and the second time around it was missing.
问题是初始目录包含 server.php 文件,第二次它丢失了。
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.
对我来说,这是与 Avast 的奇怪互动,因为它认为该文件是恶意的。检查 Avast 的病毒箱以恢复文件以避免出现更多问题。
Maybe this will save time for somebody.
也许这会为某人节省时间。
回答by Vladimir Salguero
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
项目根目录需要文件时会出现这个错误,如果你需要它可以创建文件,基本上这是必须包含的代码。
server.php
服务器.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';
回答by Kiran Maniya
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,
似乎您已经server.php
从 Laravel 项目的根目录中删除了该文件。您可以重新创建新的 server.php 并按照给定的方式放置 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';
or you can go to the official laravel github repoto grab the original server.phpfile.
或者你可以去官方的laravel github repo获取原始的server.php文件。
回答by edgan
I'm on windows 10also and I had the same issue and error message:
我也在Windows 10 上,我遇到了同样的问题和错误消息:
PHP Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
PHP Fatal error: Unknown: Failed opening required 'D:\yourProject\server.php' (include_path='C:\xampp\php\PEAR') in Unknown on line 0
PHP 警告:未知:无法打开流:第 0 行的未知中没有此类文件或目录
PHP Fatal error: Unknown: Failed opening required 'D:\yourProject\server.php' (include_path='C:\xampp\php\PEAR') in Unknown on line 0
How to solve this. On Avastantivirus:
如何解决这个问题。在Avast防病毒软件上:
Add route exception to your project path
Check if the server.php file exists on your root path project, if not it means that antivirus removed it, go to the Avast trunk and restore it.
将路由异常添加到您的项目路径
检查您的根路径项目中是否存在server.php 文件,如果不存在则表示杀毒软件已将其删除,请转到Avast 主干并恢复它。
Stop server and run it again.
停止服务器并再次运行它。