zoukankan      html  css  js  c++  java
  • tp5 解决root生成的文件,www用户没有写权限的问题

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

    出现报错

    PHP Fatal error: Uncaught exception ‘thinkexceptionErrorException’ with message ‘error_log(D:webxinluchuntian.comminishop untimelog20170211.log): failed to open stream: Permission denied’ in D:webxinluchuntian.comminishopcorelibrary hinklogdriverFile.php:98
    Stack trace:
    #0 [internal function]: thinkError::appError(2, ‘error_log(D:we…’, ‘D:webxinluchu…’, 98, Array)
    #1 D:webxinluchuntian.comminishopcorelibrary hinklogdriverFile.php(98): error_log(’[ 2017-02-11T17…’, 3, ‘D:webxinluchu…’)
    #2 D:webxinluchuntian.comminishopcorelibrary hinkLog.php(157): thinklogdriverFile->save(Array)
    #3 D:webxinluchuntian.comminishopcorelibrary hinkError.php(84): thinkLog::save()
    #4 [internal function]: thinkError::appShutdown()
    #5 {main}
    thrown in D:webxinluchuntian.comminishopcorelibrary hinklogdriverFile.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;
     

  • 相关阅读:
    软件工程结对编程作业
    软件工程第1次作业
    阅读一篇文章,培养一个习惯
    OpenvSwitch系列之五 网桥特性功能配置
    读《阿里工程师的自我修养》我学到这几点
    OpenvSwitch系列之四 ovs-ofctl命令使用
    OpenvSwitch系列之三 ovs-vsctl命令使用
    python进阶之垃圾回收
    OpenDaylight开发hello-world项目之功能实现
    python进阶之内存模型
  • 原文地址:https://www.cnblogs.com/xiaogou/p/15213372.html
Copyright © 2011-2022 走看看