【发布时间】:2019-02-10 04:19:36
【问题描述】:
几天前我将文件上传到我的cent OS服务器,它工作正常,但从今天开始我收到错误。
流或文件“/var/www/html/hasibtest/storage/logs/laravel.log” 无法打开:无法打开流:权限被拒绝
我的日志文件在哪里具有 777 权限,我也在尝试使用 0755、0644
谁能告诉我如何解决这个问题?
【问题讨论】:
几天前我将文件上传到我的cent OS服务器,它工作正常,但从今天开始我收到错误。
流或文件“/var/www/html/hasibtest/storage/logs/laravel.log” 无法打开:无法打开流:权限被拒绝
我的日志文件在哪里具有 777 权限,我也在尝试使用 0755、0644
谁能告诉我如何解决这个问题?
【问题讨论】:
首先尝试以递归方式获取目录的所有权
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(除非你知道自己在做什么)
【讨论】:
查看当前用户:<?php echo exec('whoami'); ?>
我在 ubuntu 上使用 Lampp,所以结果是 daemon
然后运行几个命令,谢谢@Shobi
sudo chown -R daemon:www-data storage
sudo chown -R daemon:www-data bootstrap/cache
现在可以了
【讨论】:
在 Centos 或 Red Hat 上
先做这个
# sestatus
如果状态已启用,则必须禁用它
# setenforce Permissive
对我来说组和用户是 nginx 所以
chown -R nginx:nginx storage bootstrap/cache
chmod -R 775 storage
chmod -R 775 bootstrap/cache
【讨论】:
尝试更改文件夹的所有者并更改文件夹的权限
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 '{}' +
【讨论】:
请注意,您必须同时更改两者。所有权和权限,以及这两个文件夹中的文件夹。 这应该影响到所有孩子
sudo chown -R apache storage
sudo chown -R apache bootstrap/cache
and
chmod -R 775 storage
chmod -R 775 bootstrap/cache
您可以查看所有者
ls -lr
该命令将显示谁拥有所有权。
【讨论】:
这应该对你有帮助
chcon -R -t httpd_sys_content_t $SITE_PATH
chcon -R -t httpd_sys_rw_content_t $SITE_PATH
【讨论】:
我找到的最短修复方法:
php artisan storage:link
sudo chown -R $USER:www-data storage bootstrap/cache
【讨论】: