前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >tp5 解决root生成的文件,www用户没有写权限的问题

tp5 解决root生成的文件,www用户没有写权限的问题

作者头像
超级小可爱
发布2023-02-17 16:53:46
发布2023-02-17 16:53:46
1.5K0
举报
文章被收录于专栏:小孟开发笔记小孟开发笔记

场景:在服务器上添加了一个定时删除cache缓存文件的任务,由于在执行之后会在runtime中生成一个文件,如果正好是月初一号就会创建这个月份的文件夹,由于这个自动任务是root用户执行,运行项目写日志是www用户,所以当项目运行再写入日志时会没有权限。

出现报错

PHP Fatal error: Uncaught exception ‘think\exception\ErrorException’ with message ‘error_log(D:\web\xinluchuntian.com\minishop\runtime\log\201702\11.log): failed to open stream: Permission denied’ in D:\web\xinluchuntian.com\minishop\core\library\think\log\driver\File.php:98

Stack trace:

#0 internal function: think\Error::appError(2, ‘error_log(D:\we…’, ‘D:\web\xinluchu…’, 98, Array)

#1 D:\web\xinluchuntian.com\minishop\core\library\think\log\driver\File.php(98): error_log(’[ 2017-02-11T17…’, 3, ‘D:\web\xinluchu…’)

#2 D:\web\xinluchuntian.com\minishop\core\library\think\Log.php(157): think\log\driver\File->save(Array)

#3 D:\web\xinluchuntian.com\minishop\core\library\think\Error.php(84): think\Log::save()

#4 internal function: think\Error::appShutdown()

#5 {main}

thrown in D:\web\xinluchuntian.com\minishop\core\library\think\log\driver\File.php on line 98

解决办法,需要修改两个位置,首先按找到thinkphp/library/log/driver/file.php

当前tp5版本:5.0.15

  1. 找到56行(不同tp版本可能会不一样,save方法中) !is_dir($path) && mkdir($path, 0755, true); 1 修改为

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

1

2.找到128行(不同tp版本可能会不一样,write方法中)

return error_log($message, 3, $destination);

1

修改为

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;

未经允许不得转载:肥猫博客 » tp5 解决root生成的文件,www用户没有写权限的问题

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档