几天前我把文件上传到我的CentOS服务器上,当时一切正常,但是从今天开始我遇到了错误。
无法打开流或文件“/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
< p > 这也是一条命令:chcon -R -t httpd_sys_rw_content_t $SITE_PATH
php artisan storage:link
sudo chown -R $USER:www-data storage bootstrap/cache