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

时间:2013-01-07 12:52:14

标签: php zend-framework

我遇到以下错误:

  

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

在我的bootstrap中,我有以下代码:

$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.tv/fbapps/www/inline/bootstrap_vengeance.php on   第81行

     

警告:fclose()要求参数1为资源,布尔值为   /home/http/me.tv/fbapps/www/inline/bootstrap_vengeance.php on   第82行

     

致命错误:带消息的未捕获异常'Zend_Log_Exception'   '“/ home /http/me.tv/fbapps/www//tmp/logs/vengeance.log”不能   以“a”中的模式打开   /home/http/me.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}引入   /home/http/me.tv/fbapps/www/library/Zend/Log/Writer/Stream.php   在第78行

3 个答案:

答案 0 :(得分:18)

将正确的权限放在文件上:0777

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

chmod 777 /home/http/me.tv/fbapps/www/tmp/logs/vengeance.log

答案 1 :(得分:1)

Web服务器用户应该有权在logs文件夹中编写和执行(传递)。

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

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

答案 2 :(得分:0)

就像克莱姆所说,您不应授予日志文件777访问权限。这是错误的,并向您的应用程序引入了漏洞。授予文件访问权限的另一种方法是授予访问权限,如下所示:

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

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

chown user:group file.log

相关问题