0

将项目从本地机器移动到生产机器后,出现以下错误:

<b>Warning</b>:  mkdir(): Permission denied in
<b>/var/www/html/findmynumber/api/v1/apache-log4php-2.3.0/src/main/php/appenders/LoggerAppenderFile.php</b> on line
<b>93</b>
<br/>
<b>Warning</b>:  log4php: [LoggerAppenderFile:myAppender]: Failed creating target directory [/var/wwww/html/findmynumber/api/v1/logs]. Closing appender. in
<b>/var/www/html/findmynumber/api/v1/apache-log4php-2.3.0/src/main/php/LoggerAppender.php</b> on line
<b>283</b>

所有者是 www-data。该组也是www-data。我什至尝试为项目文件夹提供完全权限(777),但没有成功。

log4php 的调用是:

include dirname(__FILE__) . "/apache-log4php-2.3.0/src/main/php/Logger.php"; 
Logger::configure(dirname(__FILE__) . '/apache-log4php-2.3.0/src/config.xml'); 
$log = Logger::getLogger('myLogger');

config.xml 如下所示:

<configuration>
  <appender name="myAppender" class="LoggerAppenderFile">
    <param name="file" value="/var/wwww/html/findmynumber/api/v1/logs/myLog.log"/>
  </appender>
  <appender name="console" class="LoggerAppenderConsole"/>
  <root>
    <appender_ref ref="console"/>
  </root>
  <logger name="myLogger">
    <level value="DEBUG"/>
    <appender_ref ref="myAppender"/>
  </logger>
</configuration>

我在这里想念什么?

编辑

波纹管是出现错误时的功能。它取自 LoggerAppenderFile.php 的 log4php 文件:

protected function openFile() { 
    $file = $this->getTargetFile(); 
    echo $file . "\n"; 
    $curr = !is_file($file); 
    echo "curr is: " . $curr . "\n"; 
    echo is_file($file) . "\n" ; 
    echo dirname($file) . "\n"; 
    // Create the target folder if needed 
    if(!is_file($file)) { 
        $dir = dirname($file); 

        if(!is_dir($dir)) { 
            $success = mkdir($dir, 0777, true); 
            if ($success === false) { 
                $this->warn("Failed creating target directory [$dir]. Closing appender."); 
                $this->closed = true; 
                return false; 
            } 
        } 
    }

如您所见,我自己添加了一些调试打印。第 93 行是带有 mkdir 语句的行。

4

1 回答 1

0

@florin 问题是 config.xml 中的拼写错误

 <appender name="myAppender" class="LoggerAppenderFile">
    <param name="file" value="/var/wwww/html/findmynumber/api/v1/logs/myLog.log"/>
  </appender>

应该是这样的

/var/www/html/findmynumber/api/v1/logs/myLog.log. instead of www you kept wwww 

这个你可以检查这个警告

<b>Warning</b>:  log4php: [LoggerAppenderFile:myAppender]: Failed creating target directory [/var/wwww/html/findmynumber/api/v1/logs]. Closing appender. in
于 2016-06-10T05:52:49.537 回答