Laravel 部署遇到文件权限不够无法写入日志的排查方法

Laravel tytrock ⋅ 于 2019-05-27 14:56:00 ⋅ 2772 阅读

在部署Laravel应用时,时常会遇到因权限问题无法写入日志而报错的情况

  1. Error in exception handler: The stream or file "/usr/site/laravel-app/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/laravel-app/bootstrap/compiled.php:8423

image.png


1.给storagebootstrap/cache775权限

chown -R 775 storage
chown -R 775 bootstrap/cache


2.清一下缓存和包自动发现

php artisan package:discover
php artisan config:clear
php artisan cache:clear


3.当系统为centos 7.6,查看SELinux的模式是否开了强制模式。


SELinux 共有三种模式如下:

  • Enforcing:强制模式,依据设定来限制档案资源存取。

  • Permissive:宽容模式,不限制档案资源存取,但仍会依据设定检查并记录相关讯息。

  • Disabled:停用模式,SELinux 已被停用。

默认为强制模式。


查看SELinux状态

sestatus

image.png

可以看见当前为强制模式,现在需要改为宽容模式:

setenforce Permissive

再次查看状态,现已变更为宽容模式

image.png



参考:

https://dotblogs.com.tw/echo/2017/06/19/linux_selinux_mode

https://zh.wikipedia.org/wiki/%E5%AE%89%E5%85%A8%E5%A2%9E%E5%BC%BA%E5%BC%8FLinux

回复数量: 0
    暂无评论~~
    • 请注意单词拼写,以及中英文排版,参考此页
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,使用方法请见 Emoji 自动补全来咯,可用的 Emoji 请见 :metal: :point_right: Emoji 列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
    Ctrl+Enter