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

Kyl*_*rst 10 permissions amazon-ec2 amazon-web-services laravel amazon-elastic-beanstalk

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

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

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

php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan optimize:clear
Run Code Online (Sandbox Code Playgroud)

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

又是同样的错误

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

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

/bootstrap/cache/packages.php
/bootstrap/cache/services.php
/bootstrap/cache/config.php.php
Run Code Online (Sandbox Code Playgroud)

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

sudo chmod -R 777 storage/*
Run Code Online (Sandbox Code Playgroud)

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

编辑:

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

// 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
Run Code Online (Sandbox Code Playgroud)

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

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

Kyl*_*rst 9

好吧,我得到了答案:

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 {} \;
Run Code Online (Sandbox Code Playgroud)


小智 5

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

sudo chown -R $USER:www-data storage
chmod -R 775 storage
Run Code Online (Sandbox Code Playgroud)