Laravel 5:laravel.log 无法打开:权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30306315/
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: laravel.log could not be opened: Permission Denied
提问by ied3vil
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
从一开始就阻止您,没有权限问题。/storage 是递归的chmodded 777
,整个项目文件夹由 apache:apache chown
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.
我什至将日志文件重命名为 ...-old 并且 apache 创建了一个新的...如果它没有实际的写权限,它就不会被允许创建它。
Running under CentOS release 6.6 (Final)
在 CentOS 6.6 版(最终版)下运行
Deployed the project from git, the homestead works for my colleague.
从 git 部署项目,宅基地为我的同事工作。
Full error:
完整错误:
[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
[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\n堆栈跟踪:\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 /第 84 行的 var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.phpcom/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php 第 84 行com/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php 第 84 行
回答by Jirennor
It could be that SElinux is preventing Apache from creating this file.
可能是 SElinux 阻止 Apache 创建此文件。
To test this you could disable SElinux temporally with the following command:
要对此进行测试,您可以使用以下命令暂时禁用 SElinux:
setenforce 0
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 置于许可模式。这意味着您仍然会在 SElinux 日志文件中收到一条错误消息,但 SElinux 不会阻止该命令。
To activate SElinux again you can type:
要再次激活 SElinux,您可以键入:
setenforce 1
Or reboot your CentOS server.
或者重启你的 CentOS 服务器。
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!
不幸的是,我在 CentOS 上的 Laravel 5 也有问题,原因是 SElinux。我最终禁用了 SElinux。我知道这不是正确的做法,但我还没有时间让两者一起工作!
Update
更新
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.
所以我终于有时间进一步调查这个问题,我让 SELinux 与 Laravel 5 一起工作。我刚刚为可能遇到这个问题的人更新了这篇文章。如上所述,禁用 SELinux 并不是最佳策略。
Three things need to be done:
需要做三件事:
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(/.*)?"
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"
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/
文件夹 Storage 和 Bootstrap/Cache 需要有正确的 SELinux 上下文。这可以通过以下命令实现:
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 上下文需要应用于目录:
restorecon -Rv "/var/www/<Laravel Site>/storage" restorecon -Rv "/var/www/<Laravel Site>/bootstrap/cache"
Apache 用户需要有权在两个目录中创建文件。这可以通过 CentOS 7 中的 ACL 实现:
setfacl -R -m u:apache:rwX storage/ setfacl -R -m u:apache:rwX bootstrap/cache/
The last thing you need to do is to enable SELinux again.
您需要做的最后一件事是再次启用 SELinux。
回答by Mustafa Dwekat
Try those commands for laravel 5
试试这些命令 laravel 5
$ php artisan cache:clear
$ sudo chmod -R 777 app/storage
$ composer.phar dump-autoload
This happens because laravel do not have the permissions to write to the log file, at least for my case.
发生这种情况是因为 laravel 没有写入日志文件的权限,至少在我的情况下是这样。
回答by ReesBo
This worked for me, Laravel 5.4 and above
这对我有用,Laravel 5.4 及更高版本
$ sudo chmod -R 755 storage/
$ sudo chown -R www-data storage/
$ sudo chgrp -R www-data storage/
$ php artisan cache:clear
$ php artisan config:cache
$ composer dumpautoload
Not all steps necessary.
并非所有步骤都是必需的。
回答by Lasimin
ON Laravel 5.7
在 Laravel 5.7
$ cd /var/www/html/ $ php artisan cache:clear Application cache cleared!
$ cd /var/www/html/ $ php artisan cache:clear 清除应用程序缓存!
回答by Leemarshn
for centos 7
对于centos 7
# ausearch -c 'httpd' --raw | audit2allow -M my-httpd
# semodule -i my-httpd.pp
回答by lowerends
You have to make sure the storage
folder exists. If you're deploying from git, make sure the storage
folder itself is tracked and created automatically.
您必须确保该storage
文件夹存在。如果您从 git 部署,请确保storage
自动跟踪和创建文件夹本身。