laravel centOS 7 chmod 755/775 权限被拒绝 "could not be opened: failed to open stream: Permission denied"



我有linux:

Linux版本3.10.0-693.21.1.el7.x86_64(builder@kbuilder.dev.centos.org)(gcc版本4.8.5 20150623(Red Hat4.8.5-16((GCC((#1 SMP 3月7日星期三19:03:37 UTC 2018

如果我将存储权限设置为777,laravel有效,但如果我将其设置为755或775,它会显示:

"流或文件"/home/admin/domains/linkshift.eu/public_html/storage/logs/laravel-2018-11-08.log"无法打开:无法打开流:权限被拒绝">

我尝试过搜索答案,但其他都不起作用,我尝试过Laravel在CentOS上的权限问题但仍然不起作用

编辑:我还安装了直接管理员

看起来日志文件是使用root用户生成的,并且您正在从另一个用户运行laravel。确保日志文件由同一用户编写。或者将权限授予您的用户。

sudo chown -R laravel-user:laravel-user /path/to/your/laravel/root/directory

每次部署后运行这些命令

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

仍然如果不工作,它可能也因为SELinux。

检查终端上的selinux状态:

sestatus

如果状态已启用,则写入禁用SElinux(不推荐(的命令

setenforce Permissive

或者你可以像下面这样做。

yum install policycoreutils-python -y # might not be necessary, try the below first
semanage fcontext -a -t httpd_sys_rw_content_t "/path/to/your/laravel/root/directory/storage(/.*)?" # add a new httpd read write content to sellinux for the specific folder, -m for modify
semanage fcontext -a -t httpd_sys_rw_content_t "/path/to/your/laravel/root/directory/bootstrap/cache(/.*)?" # same as the above for b/cache
restorecon -Rv /var/www/html/ # this command is very important to, it's like a restart to apply the new rules

Selinux旨在限制root用户的访问权限,因此只能访问必要的内容,至少从广义的角度来看,这是额外的安全性,禁用它不是一个好的做法,有很多链接可以学习Selinux,但在这种情况下,它甚至不是必需的。

你能显示的结果吗

ls -l /home/admin/domains/linkshift.eu/public_html/storage/logs

你试过吗

php artisan config:cache
php artisan config:clear
composer dump-autoload -o

最新更新