Laravel 5:laravel.log无法打开:权限被拒绝 [英] Laravel 5: laravel.log could not be opened: Permission Denied

查看:619
本文介绍了Laravel 5:laravel.log无法打开:权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要从头开始阻止您,没有权限问题. /storage递归chmodded 777,整个项目文件夹都被apache:apache

To stop you from the start, there is NO permission issue. /storage is recursively chmodded 777 and whole project folder is chowned by apache:apache

我什至将日志文件重命名为...-旧文件,并且apache创建了一个新文件...如果它没有实际的写许可权,则不允许创建它.

I even renamed the log file to ...-old and apache created a new one... if it didn't have actual write permissions it would not had been allowed to create it.

在CentOS 6.6版(最终版)下运行

Running under CentOS release 6.6 (Final)

从git部署了项目,这个宅基地为我的同事服务.

Deployed the project from git, the homestead works for my colleague.

完整错误:

[2015年5月18日星期一10:17:58] [错误] [客户端86.124.208.14] PHP致命 错误:未捕获的异常"UnexpectedValueException",并显示消息 '流或文件 "/var/www/vhosts/mapper.pavementlayers.com/storage/logs/laravel-2015-05-18.log" 无法打开:无法打开流:权限被拒绝" /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84\nStack 跟踪:\ n#0 /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(88): Monolog \ Handler \ StreamHandler-> write(Array)\ n#1 /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog \ Handler \ RotatingFileHandler-> write(Array)\ n#2 /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Logger.php(265): Monolog \ Handler \ AbstractProcessingHandler-> handle(Array)\ n#3 /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Logger.php(543): Monolog \ Logger-> addRecord(400,'exception'Symf ...',Array)\ n#4 /var/www/vhosts/mapper.pavementl in /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php 在第84行

[Mon May 18 10:17:58 2015] [error] [client 86.124.208.14] PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/vhosts/mapper.pavementlayers.com/storage/logs/laravel-2015-05-18.log" could not be opened: failed to open stream: Permission denied' in /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84\nStack trace:\n#0 /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(88): Monolog\Handler\StreamHandler->write(Array)\n#1 /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\RotatingFileHandler->write(Array)\n#2 /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Logger.php(265): Monolog\Handler\AbstractProcessingHandler->handle(Array)\n#3 /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Logger.php(543): Monolog\Logger->addRecord(400, 'exception 'Symf...', Array)\n#4 /var/www/vhosts/mapper.pavementl in /var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 84

推荐答案

可能是SElinux阻止了Apache创建此文件.

It could be that SElinux is preventing Apache from creating this file.

要对此进行测试,您可以使用以下命令暂时禁用SElinux:

To test this you could disable SElinux temporally with the following command:

setenforce 0

这会将SElinux置于宽松模式.这意味着您仍会在SElinux日志文件中收到错误消息,但SElinux不会阻止该命令.

This will place SElinux in permissive mode. This means that you still receive an error message in your SElinux log file but SElinux will not block the command.

要再次激活SElinux,您可以输入:

To activate SElinux again you can type:

setenforce 1

或重新启动CentOS服务器.

Or reboot your CentOS server.

不幸的是,我在CentOS上的Laravel 5也遇到了问题,原因是SElinux. 我最终禁用SElinux.我知道这不是正确的做法,但是我还没有时间让两者一起工作!

Unfortunately, I had also problems with Laravel 5 on CentOS and the cause was SElinux. I ended up with disabling SElinux. I know it is not the right thing to do but I haven't had time to get the two working together yet!

因此,我终于有时间进一步研究此问题,并让SELinux与Laravel 5一起工作.我刚刚为可能遇到此问题原因的人员更新了这篇文章.如上所述,禁用SELinux并不是最好的策略.

So I finally had sometime to investigate this further and I got SELinux working together with Laravel 5. I have just updated this post for people that might run into this issue cause. Disabling SELinux is not the best strategy as mentioned above.

需要完成三件事:

  1. 文件夹Storage和Bootstrap/Cache必须具有正确的SELinux上下文.这可以通过以下命令来实现:

  1. The folders Storage and Bootstrap/Cache need to have the right SELinux context. This can be achieved via the following commands:

semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/<Laravel Site>/storage(/.*)?"

semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/<Laravel Site>/bootstrap/cache(/.*)?"

  • 需要将SELinux上下文应用于目录:

  • The SELinux context needs to be applied on the directories:

    restorecon -Rv "/var/www/<Laravel Site>/storage"
    
    restorecon -Rv "/var/www/<Laravel Site>/bootstrap/cache"
    

  • Apache用户需要具有在两个目录中创建文件的权限.这可以通过CentOS 7中的ACL实现:

  • The Apache user needs to have the rights to create files in both directories. This can be achieved via a ACL in CentOS 7:

    setfacl -R -m u:apache:rwX storage/
    
    setfacl -R -m u:apache:rwX bootstrap/cache/
    

  • 您需要做的最后一件事是再次启用SELinux.

    The last thing you need to do is to enable SELinux again.

    这篇关于Laravel 5:laravel.log无法打开:权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆