laravel centOS 7 chmod 755/775权限被拒绝“无法打开:无法打开流:权限被拒绝”,仅当我设置为777时才允许

时间:2018-11-08 09:39:22

标签: linux laravel centos7

我有Linux:

  

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

如果我将存储权限设置为777,则laravel可以工作,但是如果我将其设置为755或775,它会显示:

  

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

我曾尝试寻找答案,但没有其他方法起作用,我曾尝试做 Permissions Issue with Laravel on CentOS 但还是不行

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

2 个答案:

答案 0 :(得分:0)

看起来该日志文件是使用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的链接,但在这种情况下,甚至不需要。

答案 1 :(得分:-2)

您能显示出

的结果吗?
  ls -l /home/admin/domains/linkshift.eu/public_html/storage/logs
 

你尝试过

  php artisan config:cache
PHP的工匠配置:清除
作曲家dump-autoload -o
 
相关问题