“storage/logs/laravel-2019-11-22.log”无法打开:无法打开流:权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/58988042/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:23:15  来源:igfitidea点击:

"storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied

laravelamazon-web-servicesamazon-ec2permissionsamazon-elastic-beanstalk

提问by Kyle Corbin Hurst

I got the following error when entering my site on a production server:

在生产服务器上输入我的站点时出现以下错误:

The stream or file "/var/app/current/storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied

流或文件“/var/app/current/storage/logs/laravel-2019-11-22.log”无法打开:无法打开流:权限被拒绝

I tried running the following commands and got Permisions denied in the terminal:

我尝试运行以下命令并在终端中拒绝权限:

php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan optimize:clear

I ran chmod -R 775 storage/logs/and composer dump-autoloadand I was able to get onto the home page of my site without any errors. After surfing around the site a bit more I was getting the same error in various areas and not in others:

我跑了chmod -R 775 storage/logs/composer dump-autoload我能够毫无错误地进入我网站的主页。在网站上浏览了更多之后,我在各个区域而不是其他区域遇到了同样的错误:

Again same error

同样的错误

The stream or file "/var/app/current/storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied

流或文件“/var/app/current/storage/logs/laravel-2019-11-22.log”无法打开:无法打开流:权限被拒绝

I deleted the following files and ran php artisan cahce:clear:

我删除了以下文件并运行php artisan cahce:clear

/bootstrap/cache/packages.php
/bootstrap/cache/services.php
/bootstrap/cache/config.php.php

The only other advice I've seen is run:

我见过的唯一其他建议是运行:

sudo chmod -R 777 storage/*

Which seems like a bad idea on a production server, but seems to be upvoted answer. Should I just give my storage director 777 permissions and why? Is there another way of fixing this?

在生产服务器上这似乎是一个坏主意,但似乎是赞成的答案。我应该给我的存储主管 777 权限吗?为什么?有没有另一种方法来解决这个问题?

Edit:

编辑:

I'm trying to do this as stated here:

我正在尝试按照此处所述进行操作:

// set current user as owner and the webserver user as the group
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
// set directory permission to be 775
chmod -R 775 storage
chmod -R 775 bootstrap/cache

but when I run sudo chown -R $USER:www-data storageI get this error:

但是当我运行时出现sudo chown -R $USER:www-data storage此错误:

chown: invalid group: ‘myusername:www-data'

chown: 无效组: 'myusername:www-data'

回答by Kyle Corbin Hurst

Alright I got the answer:

好吧,我得到了答案:

AWS AMI uses webappas the web user, not apache or ec2-useras the file shows. In that case, the webappuser has no access rights over those files.

AWS AMIwebapp用作 Web 用户,而不是 apache 或ec2-user如文件所示。在这种情况下,webapp用户对这些文件没有访问权限。

sudo chown $USER:webapp ./storage -R

find ./storage -type d -exec chmod 775 {} \;

find ./storage -type f -exec chmod 664 {} \;

回答by Computerz_man

Using the console, go to your synced folder (vagrant)

使用控制台,转到您的同步文件夹(vagrant)

sudo chown -R $USER:www-data storage
chmod -R 775 storage

回答by iAmGroot

if you done this "sudo chmod -R 777 storage" and still same error then you can go to the starage/log and delete all .log files manually.

如果你完成了这个“sudo chmod -R 777 storage”并且仍然出现同样的错误,那么你可以去 starage/log 并手动删除所有 .log 文件。

i got same problem then i tried this way. so it worked. but its not permanent solution . if this method worked for you then you can use cron job to delete automatically all logs.

我遇到了同样的问题,然后我尝试了这种方式。所以它起作用了。但它不是永久的解决方案。如果此方法对您有用,那么您可以使用 cron 作业自动删除所有日志。