【问题标题】:laravel centOS 7 chmod 755/775 permission denied"could not be opened: failed to open stream: Permission denied", only allows if I set to 777laravel centOS 7 chmod 755/775 权限被拒绝“无法打开:无法打开流:权限被拒绝”,仅当我设置为 777 时才允许
【发布时间】:2019-04-11 19:12:44
【问题描述】:

我有 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 但是还是不行

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

【问题讨论】:

  • Stackoverflow 旨在帮助程序员。这更适合超级用户社区 - superuser.com
  • 我是一名程序员,我只是想在专用服务器上托管 laravel
  • 但是好的,我会在那里发一个帖子,谢谢你的链接
  • 无论如何,我并不是说你不是程序员。我只是认为这个问题没有任何编程问题。

标签: linux laravel centos7


【解决方案1】:

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

【讨论】:

  • 我该怎么做?如何检查它是由哪个用户运行的?
  • setenforce:SELinux 已禁用,仍然无法正常工作,我应该尝试将其打开然后运行命令吗?
  • 运行这个sudo chown -R laravel-user:laravel-user /path/to/your/laravel/root/directory
  • 我也在超级用户上运行它,我还没有创建任何用户
  • 那就用 SElinux 试试运气
【解决方案2】:

你能显示结果吗

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

你试过了吗

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

【讨论】:

  • 总共 16 个 -rwxrwxrwx。 1 apache apache 14827 Nov 8 03:02 laravel-2018-11-08.log
  • 我在做 chmod -R 775 存储后尝试了一切,但仍然是流或文件“/home/admin/domains/linkshift.eu/public_html/storage/logs/laravel-2018-11-08 .log" 无法打开:无法打开流:权限被拒绝
  • 确认你的http服务器的用户名(这里假设为apache:apache),尝试删除laravel-2018-11-09.log,并设置存储权限为777再次,然后触发写入日志的执行,让 apache 创建一个新的 laravel-2018-11-09.log,然后再次执行 ls -l 以查看其所有权?
  • "total 0" 是我按照你说的做后的输出
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-31
  • 1970-01-01
  • 1970-01-01
  • 2019-08-22
  • 2013-06-05
  • 2019-05-02
  • 2018-06-27
相关资源
最近更新 更多