14

我面临以下错误:

无法使用模式“a”打开带有消息 file.log 的未捕获异常“Zend_Log_Exception”

在我的引导程序中,我有以下代码:

$logfile = PROJECT_PATH . DIRECTORY_SEPARATOR .'/tmp/logs/'.$config->app->logfile.'.log';

if (!file_exists($logfile))
{
  $fp = fopen($logfile, 'a');
  fclose($fp);
}

$redacteur = new Zend_Log_Writer_Stream($logfile);
$logger    = new Zend_Log($redacteur);

完整的错误页面:

警告:fopen(/home/http/me.tv/fbapps/www//tmp/logs/vengeance.log)[function.fopen]:无法打开流:/home/http/me 中没有这样的文件或目录。第 81 行的 tv/fbapps/www/inline/bootstrap_vengeance.php

警告:fclose() 期望参数 1 是资源,布尔值在第 82 行的 /home/http/me.tv/fbapps/www/inline/bootstrap_vengeance.php 中给出

致命错误:无法在 /home/http/me 中使用模式“a”打开带有消息“/home/http/me.tv/fbapps/www//tmp/logs/vengeance.log”的未捕获异常“Zend_Log_Exception” .tv/fbapps/www/library/Zend/Log/Writer/Stream.php:78 堆栈跟踪:#0 /home/http/me.tv/fbapps/www/inline/bootstrap_vengeance.php(85): Zend_Log_Writer_Stream-> __construct('/home/http/medi...') #1 /home/http/me.tv/fbapps/www/htdocs/vengeance/index.php(9): require_once('/home/http/medi. ..') #2 {main} 在第 78 行的 /home/http/me.tv/fbapps/www/library/Zend/Log/Writer/Stream.php 中抛出

4

3 回答 3

19

对文件赋予正确的权限:0777.

检查目录是否/home/http/me.tv/fbapps/www/tmp/logs/存在,然后在终端中运行此命令:

chmod 777 /home/http/me.tv/fbapps/www/tmp/logs/vengeance.log
于 2013-01-07T12:55:57.590 回答
2

Web 服务器用户应该有权在日志文件夹上写入和执行(通过)。

chown www-data:www-data -R logs/ # change www-data by the user of the web server chmod 755 -R logs/

将 777 放在某个地方是一个非常糟糕的主意。

于 2017-10-05T15:19:31.917 回答
0

就像克莱姆说的,你不应该给日志文件 777 访问权限。这是错误的,会给您的应用程序带来漏洞。授予文件访问权限的另一种方法是像这样授予访问权限:

chmod u=rw,g=rw,o=rw file.log

如果您只想向特定用户/组授予读写访问权限,请确保删除o=rw并添加正确的所有者/组

chown user:group file.log

于 2019-03-26T14:04:30.317 回答