Struggling to activate debug mode

I’m getting an error on my test server, but I can’t seem to activate debug mode to get details on the error.

(Disclaimer: I’m - obviously - absolutely and utterly clueless here. I’ve never worked with Kirby nor PHP before, I’m setting this up for someone else to maintain…)

Running the latest Kirby as a submodule on Ubuntu 20.04 behind nginx using php7.4-fpm.

I tried putting this in site/config/config.php:

$ cat site/config/config.php
return [
    'debug' => true
];

But that clearly isn’t working! :slight_smile:

I also tried it it with this, but that just hides the text and still doesn’t show any debug information:

$ cat site/config/config.php
<?php
return [
    'debug' => true
];

How can I fix this? Are there any other ways to find out what the error is? E.g. log files I could check for problems?

FYI, this is the nginx config:

server {
  listen 80;
  listen [::]:80;
  server_name some.ip.address;
  root        /var/www/html;
  index       index.php index.html index.htm;

  # block some common files
  location ~ (?:\.(?:bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$ {
    deny all;
  }

  # block any .htaccess files
  location ~ /\.ht {
    deny all;
  }

  location / {
    try_files $uri =404;
  }

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

An alternative way to set up error display or logging is in the php.ini file, e.g.

You can find the correct ini file via phpinfo() or typing

php --ini

in terminal-

Ok, I think I’ve got it figured out… Thanks @pixelijn for pointing me in the right direction!

Maybe this can help someone else in the future:

There wasn’t actually any PHP error happening, which is why fiddling with debug/logging settings didn’t work. :man_facepalming:

The problem was this line in the nginx site config:

location / {
    try_files $uri =404;
}

Which should be (according to Nginx issues - 500 error for media and panel 'No input file specified' - #2 by bastianallgeier):

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

What I think was happening is this: I tried visiting my.devserver.ip/, but got a 404 from nginx. Not knowing what I was doing, I tried my.devserver.ip/index.php, which got through to Kirby, but there’s not content for it, so Kirby renders a 404 page, which in PlainKit just says “Error”.

I still haven’t figured out how to turn on PHP error logging, but I noticed that php --ini gives me the .ini file for the php cli, not for fpm. The correct file on Ubuntu 20.04 is in /etc/php/7.4/fpm/php.ini.

Try setting debug mode in the config again, then create a deliberate PHP error, e.g. remove and endif statement or a semicolon… It should actually work because it enforces debug settings.

Can you be more verbose what the error looks like and what you did causing the error?

Your first config.php is missing the <?php statement, thats why you see the code on the page. Your second config.php should be ok or is there more in the file? If yes, please post the complete content of the file.

The default place for nginx log files is in /var/log/nginx/ and the files are named access.log and error.log. If your setup did not change these defaults, look into the files and post what you see at the time you get the error.

Perfect, got it displayed now. Thanks again! :heart:

Ah, thanks so much for confirming that the <?php statement is required! I’m only now seeing that the first example on Configuration | Kirby includes it, but most subsequent examples and documentation omit it. E.g. here and here.

I’m still not seeing any errors in the nginx error.logs - not sure whats going on here. phpinfo() tells me:

  • error_log = syslog
  • log_errors = On

There’s nothing relevant in /var/log/syslog nor /var/log/nginx/error.log.

In the browser I now see a pretty error rendering by something called “Whoops”. Could that somehow catch errors and prevent them from being logged?

Just tried it out with:

$ cat site/config/config.php
<?php
return [
    'debug' => true,
    'whoops' => false
];

The answer is: Yep! Now I get errors logged to /var/log/syslog. Awesome.

A <?php opening tag is required for all php code, otherwise it’s just regarded as text, so we don’t repeat it everywhere…

When you mix php with html, you also need a closing tag before you start with HTML, e.g

<?php foreach ( $page->images() as $image ) : ?> <!-- close PHP tag before we use HTML -->
  <img src="<?= $image->url() ?>">
<?php endforeach; ?><-- Open PHP tag again to continue with PHP -->

The closing tag is omitted in PHP only files, like in the config.

Gotcha, thanks!