“laravel.log” 流或文件无法打开:无法打开流:权限被拒绝。

15

几天前我把文件上传到我的CentOS服务器上,当时一切正常,但是从今天开始我遇到了错误。

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

我的日志文件已经设置为777权限,我也尝试过0755、0644权限。

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


可能是file_put_contents权限被拒绝的重复问题。 - Tobias F.
7个回答

58

首先尝试递归地获取该目录的所有权

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”。 - Aashwiin Roghan

7

检查当前用户:<?php echo exec('whoami'); ?>

我正在使用Ubuntu上的LAMPP,因此结果是daemon

然后运行几个命令,感谢@Shobi的帮助。

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

现在它可以工作了


5

在CentOS或Red Hat上

首先执行以下操作:

 # sestatus

如果状态已启用,则必须将其禁用。

# setenforce Permissive

对我来说,组和用户都是nginx

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

最终,这是真正的解决方案,非常感谢。 - Camilo Lizarazo

3

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

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 '{}' +

2
请注意,您必须同时更改这两个文件夹中的所有权和权限以及文件夹。这应该会影响到所有子文件夹。
sudo chown -R apache storage
sudo chown -R apache bootstrap/cache

and

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


您可以检查所有者。
ls -lr 

那个命令将显示拥有者是谁。


1
这应该会对你有所帮助 < p > 这里是命令:chcon -R -t httpd_sys_content_t $SITE_PATH

< p > 这也是一条命令:chcon -R -t httpd_sys_rw_content_t $SITE_PATH


0
我找到的最简单的解决方法是:
php artisan storage:link
sudo chown -R $USER:www-data storage bootstrap/cache

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接