【问题标题】:"The stream or file "laravel.log" could not be opened: failed to open stream: Permission denied"“无法打开流或文件“laravel.log”:无法打开流:权限被拒绝”
【发布时间】:2019-02-10 04:19:36
【问题描述】:

几天前我将文件上传到我的cent OS服务器,它工作正常,但从今天开始我收到错误。

流或文件“/var/www/html/hasibtest/storage/logs/laravel.log” 无法打开:无法打开流:权限被拒绝

我的日志文件在哪里具有 777 权限,我也在尝试使用 0755、0644

谁能告诉我如何解决这个问题?

【问题讨论】:

标签: php laravel-5 centos


【解决方案1】:

首先尝试以递归方式获取目录的所有权

sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache

然后使用以下设置正确的目录访问权限

chmod -R 775 storage
chmod -R 775 bootstrap/cache

永远不要将目录权限设置为 777(除非你知道自己在做什么)

【讨论】:

  • 对于我的用例,我不得不将 www-data 替换为 'apache'
【解决方案2】:

查看当前用户:<?php echo exec('whoami'); ?> 我在 ubuntu 上使用 Lampp,所以结果是 daemon

然后运行几个命令,谢谢@Shobi

sudo chown -R daemon:www-data storage
sudo chown -R daemon:www-data bootstrap/cache

现在可以了

【讨论】:

    【解决方案3】:

    在 Centos 或 Red Hat 上

    先做这个

     # sestatus
    

    如果状态已启用,则必须禁用它

    # setenforce Permissive
    

    对我来说组和用户是 nginx 所以

    chown -R nginx:nginx storage bootstrap/cache
    chmod -R 775 storage
    chmod -R 775 bootstrap/cache
    

    【讨论】:

    • 终于,这才是真正的解决方案,非常感谢
    【解决方案4】:

    尝试更改文件夹的所有者并更改文件夹的权限

    sudo chown -R www-data storage/logs/
    sudo chmod g+w -R storage/logs
    

    现在对子文件夹日志应用所有规则

    cd storage/logs
    sudo find . -type d -exec chmod g+s '{}' +
    

    【讨论】:

      【解决方案5】:

      请注意,您必须同时更改两者。所有权和权限,以及这两个文件夹中的文件夹。 这应该影响到所有孩子

      sudo chown -R apache storage
      sudo chown -R apache bootstrap/cache
      
      and
      
      chmod -R 775 storage
      chmod -R 775 bootstrap/cache
      
      

      您可以查看所有者

      ls -lr 
      

      该命令将显示谁拥有所有权。

      【讨论】:

        【解决方案6】:

        这应该对你有帮助

        chcon -R -t httpd_sys_content_t $SITE_PATH

        chcon -R -t httpd_sys_rw_content_t $SITE_PATH

        【讨论】:

          【解决方案7】:

          我找到的最短修复方法:

          php artisan storage:link
          sudo chown -R $USER:www-data storage bootstrap/cache
          

          【讨论】:

            猜你喜欢
            • 2018-05-06
            • 2018-10-03
            • 2020-06-16
            • 2018-07-08
            • 2019-06-30
            • 2021-10-03
            • 2020-08-29
            • 2013-01-22
            • 2021-02-09
            相关资源
            最近更新 更多