【laravel】centos上部署laravel项目,出现storage目录权限问题

The stream or file "/var/www/blog/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied

image

解决:让httpd以root身份运行或laravel项目创建者身份运行

  • cd /etc/httpd/conf
  • cp -p httpd.conf httpd.conf.copy
  • vim httpd.conf

找到这一项:

User apache
Group apache

修改成:

User root
Group root
  • systemctl restart httpd

原理:

centos下的目录对访问者有身份要求,一般是

  • 所有者拥有 读,写,执行 权限
  • 组成员拥有 读,执行权限
  • 其他成员只能读

而用yum install -y httpd安装完apache后,默认是使用apache这个身份来运行httpd服务的,所以没法在storage目录下创建log文件
在laravel项目文件夹下ll打印一下可以看到:

image

其他人对storage文件夹只有读和执行的权限: drwxrwxr-x d表示directory,后面的字母分为3组,每3个一组,第一组表示创建者的权限,读、写、执行;第二组表示组成员的权限,读、写、执行;第三组表示其他人的权限,读、执行。

建议不要用root身份运行,再创建个用户专门来运行httpd服务

posted @ 2021-05-16 21:54  蜜蜂老牛黄瓜  阅读(2067)  评论(0编辑  收藏  举报