我有Linux:
Linux version 3.10.0-693.21.1.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Wed Mar 7 19:03:37 UTC 2018
如果我将存储权限设置为 777,laravel 可以工作,但如果我将其设置为 755 或 775,它会显示:
"The stream or file "/home/admin/domains/linkshift.eu/public_html/storage/logs/laravel-2018-11-08.log" could not be opened: failed to open stream: Permission denied"
我尝试过寻找答案,但没有其他效果,我尝试过这样做 Permissions Issue with Laravel on 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 的链接,但对于这种情况甚至不需要。
关于linux - laravel centOS 7 chmod 755/775 权限被拒绝“无法打开 : failed to open stream: Permission denied", 仅允许我设置为 777,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53205011/