记录一个 tp5 写入日志权限 root跟www权限问题

本文讲述了如何修复ThinkPHP中CLI日志写入冲突,通过修改File.php文件,解决目录权限不足导致的错误,包括创建目录并设置777权限,确保www应用正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

cli 日志 先行写入 导致 www后续根本写不进去 直接出错。 没有目录权限 没有写入权限
先附上错误信息

  thrown in /usr/local/nginx/html/diaodu/thinkphp/library/think/log/driver/File.php on line 245" while reading response header from upstream, client: 192.168.0.110, server: 127.0.0.1, request: "OPTIONS /api/chat_api/upload HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.10.100:8181", referrer: "https://192.168.10.100/"
2021/02/20 17:55:01 [error] 3952#0: *31 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught think\exception\ErrorException: Undefined index: timestamp in /usr/local/nginx/html/diaodu/thinkphp/library/think/log/driver/File.php:245
Stack trace:

修改方案 百度的 - -
首先按找到thinkphp/library/log/driver/file.php

!is_dir($path) && mkdir($path, 0755, true);

修改为

 !is_dir($path) && mkdir($path, 0755, true)  && chmod($path,0777);
return error_log($message, 3, $destination);

修改为

if (!is_file($destination)) {
            $first = true;
        }

        $ret = error_log($message, 3, $destination);
        try {
            if (isset($first) && is_file($destination)) {
                chmod($destination, 0777);
                unset($first);
            }
        } catch (\Exception $e) {

        }
        return $ret;

最后记得重启 cli的应用程序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值