Php log4php mkdir 权限被拒绝
Php log4php mkdir permission denied
将项目从本地机器移动到生产机器后,出现以下错误:
<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>
我在这里错过了什么?
编辑
下面是出现错误的函数。它取自 log4php 文件,来自 LoggerAppenderFile.php:
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语句的。
@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
将项目从本地机器移动到生产机器后,出现以下错误:
<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>
我在这里错过了什么?
编辑
下面是出现错误的函数。它取自 log4php 文件,来自 LoggerAppenderFile.php:
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语句的。
@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