【问题标题】:Uncaught exception 'Zend_Log_Exception' with message file.log cannot be opened with mode "a"无法使用模式“a”打开带有消息 file.log 的未捕获异常“Zend_Log_Exception”
【发布时间】:2013-01-07 12:52: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.tv/fbapps/www/inline/bootstrap_vengeance.php 上 第 81 行

警告:fclose() 期望参数 1 是资源,布尔值在 /home/http/me.tv/fbapps/www/inline/bootstrap_vengeance.php 上 第 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 行

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • 我对整个目录拥有“755”权限,但该文件不存在。将目录的权限更改为“777”解决了这个问题。
      • 我已经把 chmod 777 放在文件和目录上。PHPUnit 仍然给我同样的错误信息。 cannot be opened in mode "a"
      • 如果您根据日期创建日志文件,这不是一个很好的解决方案
      • 通过引入安全漏洞来解决问题不是可接受的解决方案。只需将正确的权利授予正确的用户即可。
      【解决方案3】:

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

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

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

      chown user:group file.log

      【讨论】:

        猜你喜欢
        • 2014-08-24
        • 2014-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-01
        • 1970-01-01
        • 2016-02-27
        相关资源
        最近更新 更多