【问题标题】:"storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied“storage/logs/laravel-2019-11-22.log”无法打开:无法打开流:权限被拒绝
【发布时间】:2020-03-18 03:50:22
【问题描述】:

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

无法打开流或文件“/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

我运行了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

我看到的唯一其他建议是运行:

sudo chmod -R 777 storage/*

这在生产服务器上似乎是个坏主意,但似乎是赞成的答案。我应该只给我的存储主管 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

但是当我运行sudo chown -R $USER:www-data storage 时,我得到了这个错误:

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

【问题讨论】:

  • 给目录775权限,给文件664权限
  • 好的,chmod -R 775 storage/logs/,您可以授予可能尚未创建的文件的权限吗?我不确定该怎么做?
  • 我说的是laravel中所有文件和文件夹的权限,你可以这样:sudo find /path/to/your/laravel/root/directory -type f -exec chmod 664 {} \;sudo find /path/to/your/laravel/root/directory -type d -exec chmod 775 {} \;
  • 这些是我在安装 Laravel 项目后经常使用的命令,它们运行良好。从应用程序的根目录运行sudo chown $USER:http ./storage -R 然后sudo chown $USER:http ./bootstrap/cache -R 然后find ./storage -type d -exec chmod 775 {} \; 然后find ./storage -type f -exec chmod 664 {} \; 然后find ./bootstrap/cache -type d -exec chmod 775 {} \;
  • 对不起,我昨天迟到了继续讨论。我检查了您提供的链接,从那里的内容来看,服务器的用户名是apache,所以您可以尝试使用sudo chown $USER:apache ./storage -R,然后是find ./storage -type d -exec chmod 775 {} \;find ./storage -type f -exec chmod 664 {} \;。我不确定 AWS 服务是否可以肯定地说出来,但总而言之,您必须找到服务器使用的用户名,并授予它对 /storage/bootstrap/cache 目录和子目录的写入权限。

标签: laravel amazon-web-services amazon-ec2 permissions amazon-elastic-beanstalk


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    好的,我得到了答案:

    AWS AMI 使用 webapp 作为 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 {} \;
    

    【讨论】:

    • 运行 ps aux 并查看用户在运行 php-fpm 并将用户更改为对我有用的用户......由于某种原因,用户是 www-data
    猜你喜欢
    • 2019-08-09
    • 2019-09-10
    • 1970-01-01
    • 2018-07-08
    • 2018-05-06
    • 2018-10-03
    • 2020-06-16
    • 2021-10-03
    • 2021-10-03
    相关资源
    最近更新 更多