Where does Kirby store its logs?

(Or maybe the question is: how do I configure php-fpm to log Kirby errors?)

I’m running Kirby 3 behind nginx using php-fpm on Ubuntu 20.04.

I recently ran into a “This page is currently offline due to an unexpected error” error message and wanted to see what the problem was without having to turn on debug mode.

I’ve looked in /var/log/php7.4-fpm.log, /var/log/syslog, /var/log/nginx/error.log but found nothing.

Maybe this helps, has nothing to do with Kirby but with your PHP configuration:

https://www.php.net/manual/en/install.fpm.configuration.php

Hm, the config has (among other things):

error_log = /var/log/php7.4-fpm.log
log_level = notice

Shouldn’t this mean that - if Kirby is logging errors (I take from your comment that it does so by default?) - I should see error messages in /var/log/php7.4-fpm.log? Yet it’s empty…

This has nothing to do with Kirby but with PHP, you need to tell PHP to log errors

https://www.php.net/manual/de/function.error-reporting.php

Strange. I must be missing something obvious.

/etc/php/7.4/fpm/php.ini has:

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
log_errors = On

Still, no logs anywhere I can see. (I have a page that throws an error, so there should be something…)

You can briefly set the debug option to true in your config, but that is no permanent solution, of course.

Did some more testing and I think this might be an issue with Kirby after all. Using plain PHP (no Kirby) with my existing PHP settings, I can get errors logged just fine!

Any help with this would be hugely appreciated.

Without Kirby

If I use this nginx config:

server {
  listen 80 default_server;
  root /var/www/html;

  location / {
    try_files $uri $uri/ /index.php$is_args$args;
  }

  location /index.php {
    include      snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  }
}

And put this file in /var/www/html/index.php:

<?= noSuchFunction() ?>

Then, when I run curl localhost/index.php, I get the following output in /var/log/nginx/error.log:

2021/03/03 10:58:18 [error] 31857#31857: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function noSuchFunction() in /var/www/html/index.php:1
Stack trace:
#0 {main}
  thrown in /var/www/html/index.php on line 1" while reading response header from upstream, client: 127.0.0.1, server: , request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "localhost"

Nice!

With Kirby

If I now try to reproduce this with Kirby, I still don’t get any error logs.

Keeping the same nginx config, I put this in /var/www/html/site/templates/home.php

<?= noSuchFunction() ?>

Now when I run curl localhost/home, I get a 500 error repsonse, but no output regarding the error in the nginx error log or anywhere else.

My current Kirby config, in case it’s relevant:

<?php
return [
  'auth' => [
    'methods' => 'code'
  ],
  'cache' => [
    'pages' => [
      'active' => false
    ]
  ],
  'languages' => true,
  'panel' => [
    'install' => true
  ]
];