php 无法以模式“a”打开带有消息 file.log 的未捕获异常“Zend_Log_Exception”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14196352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught exception 'Zend_Log_Exception' with message file.log cannot be opened with mode "a"
提问by j0k
I'm facing the following error:
我面临以下错误:
Uncaught exception 'Zend_Log_Exception' with message file.log cannot be opened with mode "a"
无法以模式“a”打开带有消息 file.log 的未捕获异常“Zend_Log_Exception”
In my bootstrap I have the following code:
在我的引导程序中,我有以下代码:
$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);
The full error page:
完整的错误页面:
Warning: fopen(/home/http/me.tv/fbapps/www//tmp/logs/vengeance.log) [function.fopen]: failed to open stream: No such file or directory in /home/http/me.tv/fbapps/www/inline/bootstrap_vengeance.php on line 81
Warning: fclose() expects parameter 1 to be resource, boolean given in /home/http/me.tv/fbapps/www/inline/bootstrap_vengeance.php on line 82
Fatal error: Uncaught exception 'Zend_Log_Exception' with message '"/home/http/me.tv/fbapps/www//tmp/logs/vengeance.log" cannot be opened with mode "a"' in /home/http/me.tv/fbapps/www/library/Zend/Log/Writer/Stream.php:78 Stack trace: #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} thrown in /home/http/me.tv/fbapps/www/library/Zend/Log/Writer/Stream.php on line 78
警告: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 是资源,布尔值在第 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 中抛出
回答by j0k
Put the right permission on the file: 0777.
为文件赋予正确的权限:0777.
Check if the directory /home/http/me.tv/fbapps/www/tmp/logs/exists, then run this command in a terminal:
检查目录是否/home/http/me.tv/fbapps/www/tmp/logs/存在,然后在终端中运行此命令:
chmod 777 /home/http/me.tv/fbapps/www/tmp/logs/vengeance.log
回答by Clem
The web server user should have the right to write and exec (to pass through) on the logs folder.
Web 服务器用户应该有权在日志文件夹上写入和执行(通过)。
chown www-data:www-data -R logs/ # change www-data by the user of the web server
chmod 755 -R logs/
chown www-data:www-data -R logs/ # change www-data by the user of the web server
chmod 755 -R logs/
It s a very bad idea to put 777 somewhere.
把 777 放在某个地方是一个非常糟糕的主意。
回答by tupan
Like Clem said, you should not give a log file 777 access. It is wrong and introduces vulnerabilities to your app. Another way to give access to your file is giving access like this:
就像 Clem 所说的,你不应该给日志文件 777 访问权限。这是错误的,并为您的应用程序引入了漏洞。另一种授予文件访问权限的方法是授予如下访问权限:
chmod u=rw,g=rw,o=rw file.log
chmod u=rw,g=rw,o=rw file.log
If you want to give read and write access only to specific user/groups make sure you remove the o=rwand add the proper owner/group
如果您只想授予特定用户/组的读写访问权限,请确保删除o=rw并添加正确的所有者/组
chown user:group file.log
chown user:group file.log

