Skip to content
Kirby 6 is here! Learn more

Debugging

Screencast

Debug mode

Kirby's debug mode is super helpful for finding mistakes in your templates, snippets or other parts of your project.

This video is loaded from YouTube servers with your consent. Read more…

Debug mode

Kirby honours your PHP error logging settings by default. If you've switched off error logging, you won't get any errors and might end up with a white screen.

Especially on your local machine, we recommend to switch on error logging in your php.ini. Kirby also has a built-in option which tries to enforce this:

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

Add this to /site/config/config.php in order to show errors immediately.

Make sure to disable debug mode in production! Displaying PHP errors on a public server can be a serious security risk:

  • Error messages are displayed with detailed information about the code structure (e.g. file path, class, method)
  • With Whoops enabled, there will be even more detailed information about the code structure
  • Detailed error messages for login failures could leak information to attackers

In a production environment, always log errors to your PHP error logs.

Errors in the Panel

When a request in the Panel fails, a dialog shows the error message and the request: path, query, HTTP method and status code. In debug mode, it adds the exception with its class, file and line, any additional details and the full stack trace.

Request error dialog with the error message, the request, the exception and the stack trace

File paths are shortened to placeholders like {kirby}, {site} or {index}, so that error responses don't expose the folder structure of your server. With the editor option, you can open the file of the exception and each entry of the stack trace right at the line in your code editor.

When changes can't be saved because some fields are invalid, a dialog lists every issue, grouped by field:

Validation error dialog listing the issues of three fields

var_dump

If you need to inspect one of Kirby's objects, such as $site, $page or any $file, we recommend to use var_dump:

var_dump($page);

It's a bit like PHP's equivalent of console.log() in JavaScript.

The output of var_dump() will be massively improved if you have Xdebug installed on your machine. Xdebug is most likely pre-installed if you use MAMP.

Bugs

If you run into an issue that you can't fix yourself and which seems like a Kirby bug, please post it on the forum in the issues category. We will take it from there and either try to help you out or move it to our official issue tracker on GitHub if it really turns out to be a bug.