Uncaught exception 'Zend_Log_Exception' with message file.log cannot be opened with mode "a"
Asked Answered
B

4

14

I'm facing the following error:

Uncaught exception 'Zend_Log_Exception' with message file.log cannot be opened with mode "a"

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

Basilicata answered 7/1, 2013 at 12:52 Comment(0)
T
19

Put the right permission on the file: 0777.

Check if the directory /home/http/me.tv/fbapps/www/tmp/logs/ exists, then run this command in a terminal:

chmod 777 /home/http/me.tv/fbapps/www/tmp/logs/vengeance.log
Territorialism answered 7/1, 2013 at 12:55 Comment(4)
I had permissions '755' on the whole directory and the file didn't exist. Changing permissions on the directory to '777' solved the issue.Declivity
I've put chmod 777 on both the file AND the directory.. PHPUnit is sitll giving me the same error message. cannot be opened in mode "a" Broyles
this is not much of a solution if you create log file based on datesOverwinter
Solving an issue by introduting a security breach is not an acceptable solution. Just give the right right to the right user.Brocade
B
2

The web server user should have the right to write and exec (to pass through) on the logs folder.

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.

Brocade answered 5/10, 2017 at 15:19 Comment(0)
T
0

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:

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=rw and add the proper owner/group

chown user:group file.log

Timothea answered 26/3, 2019 at 14:4 Comment(0)
M
0

I had faced the same problem, and it was a user root issue on ubuntu

you just first check all the directory and the subdirectory permissions then run the command

chown /xxx/xxxx/xxx.log -R

and your project should run on the browser

Mullens answered 11/8 at 7:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.