php Laravel 5 显示 ErrorException file_put_contents 无法打开流:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46959985/
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 5 show ErrorException file_put_contents failed to open stream: No such file or directory
提问by Evgeniy
I have a project on Laravel 5 and I work with it at the office and at home too. It works fine, but recently at home it stopped working. Laravel show me two ErrorException
我有一个关于 Laravel 5 的项目,我也在办公室和家里使用它。它工作正常,但最近在家里它停止工作。Laravel 向我展示了两个 ErrorException
file_put_contents(G:\project\storage\framework\views/751d8a0fd8a7d4138c09ceb6a34bb377aa2d6265.php):
failed to open stream: No such file or directory
and
和
file_put_contents(G:\project\storage\framework/sessions/aIXycR4LIAUBVIqZu0T590paOMIpV8vfZGIroEp0):
failed to open stream: No such file or directory
I'm searching problem decision with Google and find information about correct rights. All advice is about Linux, but I'am work in Windows at the office and at home too.
我正在使用 Google 搜索问题决策并查找有关正确权利的信息。所有的建议都是关于 Linux 的,但我也在办公室和家里使用 Windows。
When I try to clear application cache and view cache, artisan talk to me - ...cleared. But cache data and views are present in storage.
当我尝试清除应用程序缓存和查看缓存时,工匠与我交谈 - ...已清除。但是缓存数据和视图存在于存储中。
How can I fix this problem?
我该如何解决这个问题?
Thanks in advance!
提前致谢!
采纳答案by Evgeniy
After some research I understand - I have very similar, but different root project locations and its cached in /bootstrap/cache
. After cache clearing project started.
经过一番研究,我明白了 - 我有非常相似但不同的根项目位置,并且它缓存在/bootstrap/cache
. 缓存清除项目启动后。
回答by Amit Verma
The best way to solve this problem is, go to directory laravel/bootstrap/cache
and delete config.php
file. or you can rename it as well like config.php.old
And your problem will be fix.
Happy coding :-)
解决此问题的最佳方法是转到目录laravel/bootstrap/cache
并删除config.php
文件。或者您也可以将其重命名为config.php.old
您的问题将得到解决。快乐编码:-)
回答by Elisha Senoo
You should typically run the php artisan config:cache
command as part of your production deployment routine. As a solution to your problem, I suggest you
您通常应该将php artisan config:cache
命令作为生产部署例程的一部分运行。作为您问题的解决方案,我建议您
- Recreate the cache file, for faster configuration loading
- 重新创建缓存文件,以加快配置加载
To do this, run the following Artisan commands on your command line
为此,请在命令行上运行以下 Artisan 命令
php artisan config:cache
php artisan config:cache
Where you don't have access to the command line on your server, you can programmatically execute the command by adding the following to your routes:
如果您无权访问服务器上的命令行,则可以通过将以下内容添加到路由中以编程方式执行命令:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('config:cache');
return 'DONE'; //Return anything
});
And then call the clear-cache
route from your browser.
然后clear-cache
从浏览器调用路由。
I hope this is helpful.
我希望这是有帮助的。
回答by shivanikoko
Actually I faced this issue when I moved my project from server to local.
实际上,当我将项目从服务器移动到本地时,我遇到了这个问题。
in
在
storage/framework
存储/框架
four basic folders are required cache, sessions, testing, views
四个基本文件夹是必需的缓存、会话、测试、视图
In My case sessions was missing might be in gitignore.
在我的情况下,会话丢失可能在 gitignore 中。
So I manually created session folder and refreshed browser and it was working.
所以我手动创建了会话文件夹并刷新了浏览器,它正在工作。
So any of the missing folder if we delete this problem can be solved.
所以任何丢失的文件夹如果我们删除这个问题就可以解决。
回答by Bijaya Kumar Oli
This type of issue generally occurs while migrating one server to another, one folder to another. Laravel keeps the cache and configuration (file name ) when the folder is different then this problem occurs.
将一台服务器迁移到另一台服务器,将一个文件夹迁移到另一台服务器时,通常会出现此类问题。当文件夹不同时,Laravel 会保留缓存和配置(文件名),然后就会出现此问题。
Solution Run Following command:
解决方案运行以下命令:
php artisan config:cache
https://laravel.com/docs/5.6/configuration#configuration-caching
https://laravel.com/docs/5.6/configuration#configuration-caching
回答by Azeirah
Apache + WSL on windows
Windows 上的 Apache + WSL
This is a silly mistake, and a different answer compared to the others, but I'll add it because it happened to me.
这是一个愚蠢的错误,与其他答案相比,这是一个不同的答案,但我会添加它,因为它发生在我身上。
If you use WSL (linux bash on windows) to manage your laravel application, while using your windowsapache to run your server, then running any caching commands in the wsl will store the linux pathrather than the windows pathto the sessions and other folders.
如果您使用 WSL(windows 上的 linux bash)来管理您的 Laravel 应用程序,同时使用您的windowsapache 运行您的服务器,那么在 wsl 中运行任何缓存命令将存储linux 路径而不是会话和其他文件夹的windows 路径.
Solution
解决方案
Simply run the cache clearing commands in the powershell, rather than in WSL.
只需在powershell 中运行缓存清除命令,而不是在 WSL 中。
$ php artisan optimize
Was enough for me.
对我来说已经足够了。
回答by Dibyendu Mitra Roy
In case of shared hosting when you do not have command line access simply navigate to laravel/bootstrap/cache folder and delete (or rename) config.php and you are all done!
如果您没有命令行访问权限的共享主机,只需导航到 laravel/bootstrap/cache 文件夹并删除(或重命名)config.php 就完成了!
回答by Rasheduzzaman
The best way to solve this problem is, go to directory laravel/bootstrap/cache
and delete all files from cache.
解决此问题的最佳方法是,转到目录laravel/bootstrap/cache
并从缓存中删除所有文件。
To do this, run the following Artisan commands on your command line1. php artisan config:clear
2. php artisan cache:clear
3. php artisan config:cache
为此,请在命令行上运行以下 Artisan 命令1. php artisan config:clear
2. php artisan cache:clear
3. php artisan config:cache
In your panel or server, you can execute commands by adding the following to your routes:
在您的面板或服务器中,您可以通过将以下内容添加到您的路由中来执行命令:
Route::get('/clear-cache', function() {
$run = Artisan::call('config:clear');
$run = Artisan::call('cache:clear');
$run = Artisan::call('config:cache');
return 'FINISHED';
});
And then call the?www.yourdomain.com/clear-cache
?route from your browser.
然后调用? www.yourdomain.com/clear-cache
?从浏览器路由。
回答by Carlos Avalos
Try with these commands that have been useful with those errors
尝试使用这些对这些错误有用的命令
path\project\storage\framework\views...
路径\项目\存储\框架\视图...
php artisan view:clear
path\project\storage\framework/sessions...
路径\项目\存储\框架/会话...
php artisan config:cache
回答by Roshan Aravinda
The reason for this problem is the cache files in localhost. According to that I've tried several things as follows to clear the cache on my project, but every time I've failed.
这个问题的原因是本地主机中的缓存文件。据此,我尝试了以下几种方法来清除我项目中的缓存,但每次都失败了。
- Tried to clear cahe commands by changing web.php file (with artisan codes)
- Tried to clear cache by connecting SSH (via PUTTY)
- Tried to host my project in Sub domain within create a new Publicdirectory
- 试图通过更改 web.php 文件(使用工匠代码)来清除 cahe 命令
- 尝试通过连接 SSH(通过 PUTTY)清除缓存
- 试图在创建一个新的公共目录的子域中托管我的项目
So I've found a solution for this problem after each and every above steps failed and it worked for me perfectly. I deleted the cache.phpfile in host_route/bootstrap/cachedirectory.
因此,在上述每个步骤都失败后,我找到了解决此问题的方法,并且对我来说效果很好。我删除了host_route /bootstrap/cache目录中的cache.php文件。
I think this answer will help your problem.
我认为这个答案将帮助您解决问题。