php “laravel.log”无法打开:无法打开流
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24055056/
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.log" could not be opened: failed to open stream
提问by Josh Mountain
I have setup Laravel homestead on a local OSX machine, everything seemed to be going smoothly until I tried to open example.app:8000 and got this error:
我在本地 OSX 机器上设置了 Laravel homestead,一切似乎都很顺利,直到我尝试打开 example.app:8000 并出现此错误:
Error in exception handler: The stream or file "/home/vagrant/Code/example/app/storage/logs/laravel.log" could not be opened: failed to open stream: Protocol error in /home/vagrant/Code/example/bootstrap/compiled.php:8671
I followed the Laravel docs as well as a Laracast about setting up homestead, so I am not sure what would be causing this. I can see that /home/vagrant/Code/example/app/storage/logs/laravel.log
doesn't exist, but I assume that is something that should be created automatically?
我遵循了 Laravel 文档以及关于设置宅基地的 Laracast,所以我不确定是什么导致了这种情况。我可以看到它/home/vagrant/Code/example/app/storage/logs/laravel.log
不存在,但我认为应该自动创建它?
采纳答案by Chirag Shah
You need to run one of the following:
您需要运行以下其中一项:
sudo chmod -R 644 app/storage
sudo chmod -R 755 app/storage
sudo chmod -R 644 app/storage
sudo chmod -R 755 app/storage
回答by Daniel A.A. Pelsmaeker
All files and folders under app/storage
should be writableby you and group www-data(the webserver).
您和www-data组(网络服务器)下的所有文件和文件夹app/storage
都应该是可写的。
Error in exception handler: The stream or file "laravel/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in laravel/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:77
异常处理程序中的错误:无法打开流或文件“laravel/app/storage/logs/laravel.log”:无法打开流:laravel/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler 中的权限被拒绝.php:77
If you get this error (or a similar error) in the browser when accessing your site, then the group www-data
can't write to app/storage
. If you get this error when you execute certain php artisan
commands, then you (the user) can't write to app/storage
. Therefore both you and the www-data group must have write permission.
如果您在访问您的网站时在浏览器中收到此错误(或类似错误),则该组www-data
无法写入app/storage
. 如果您在执行某些php artisan
命令时遇到此错误,则您(用户)无法写入app/storage
. 因此,您和 www-data 组都必须具有写入权限。
To ensure the files and folders have the correct permissions:
要确保文件和文件夹具有正确的权限:
Go to the root of your Laravel installation (where
composer.json
andartisan
live).Change the owning user and group, where
yourusername
is your username:sudo chown -R yourusername:www-data app/storage
This recursively (
-R
) sets the user:group owners toyourusername:www-data
in all files and folders fromapp/storage
onward.Add the write permission for both you and the
www-data
group:sudo chmod -R ug+w app/storage
This recursively (
-R
) adds (+
) the write flag (w
) to the user (u
) and group (g
) that own the files and folders fromapp/storage
onward.Additionally, some suggest you may need to flush the application cache.
php artisan cache:clear
Finally, you may want to regenerate Composer's autoload files.
composer dump-autoload
转到你的 Laravel 安装的根目录(where
composer.json
andartisan
live)。更改拥有用户和组,
yourusername
您的用户名在哪里:sudo chown -R yourusername:www-data app/storage
这递归地 (
-R
) 将 user:group 所有者设置为yourusername:www-data
从app/storage
以后的所有文件和文件夹中。为您和
www-data
组添加写入权限:sudo chmod -R ug+w app/storage
这递归地 (
-R
) 添加 (+
) 写入标志 (w
) 到拥有文件和文件夹的用户 (u
) 和组 (g
)app/storage
。此外,有些人建议您可能需要刷新应用程序缓存。
php artisan cache:clear
最后,您可能希望重新生成 Composer 的自动加载文件。
composer dump-autoload
回答by Chirag Shah
As for me I had changed my storage permission with chmod -R 777 storage
and it's work well.
至于我,我已经更改了我的存储权限,chmod -R 777 storage
并且运行良好。
However, setting 777 permissions is incredibly dangerous and should not be done on any server other than your local machine.
但是,设置 777 权限非常危险,不应在本地计算机以外的任何服务器上进行。
I had checked for this configuration at here.
我已经在这里检查了这个配置。
回答by Owais Alam
You can do this by following steps
您可以按照以下步骤执行此操作
chmod -R 775 storage
which means
意思是
7 - Owner can write
7 - Group can write
5 - Others cannot write!
If your webserver is not running as Vagrant, it will not be able to write to it, so you have 2 options:
如果您的网络服务器不是作为 Vagrant 运行,它将无法写入,因此您有 2 个选择:
chmod -R 777 storage (do not do this)
or change the group to your webserver user, supposing it's www-data:
或者将组更改为您的网络服务器用户,假设它是 www-data:
chown -R vagrant:www-data storage
回答by Drellgor
If changing the file permissions as described in the other answers didn't work and you're using CentOS 7 or RHEL then the issue may be a security program called selinux. I struggled with all kinds of permissions and groups before noticing user3670777 answer to Laravel 4: Failed to open stream: Permission denied
如果按照其他答案中的描述更改文件权限不起作用,并且您使用的是 CentOS 7 或 RHEL,那么问题可能是名为 selinux 的安全程序。在注意到 user3670777 对Laravel 4 的回答之前,我一直在努力处理各种权限和组:无法打开流:权限被拒绝
Hope this helps others.
希望这对其他人有帮助。
回答by Sachin Parulkar
If All Above suggestions not working disable your selinux and try again
如果以上所有建议都不起作用,请禁用您的 selinux 并重试
回答by Jay
im pretty new on laravel. May be I could not explain it in depth but that command fixed my problem.
我在 Laravel 上很新。可能是我无法深入解释它,但该命令解决了我的问题。
chmod -R 777 storage/