Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

A better error page for Symfony applications

Original – by Freek Van der Herten – 2 minute read

Ignition is the most beautiful error page for PHP apps. Yesterday, we launched a new major version of Ignition - you can check out all the details in this blog post.

Ignition used to be Laravel specific, but we've now created a framework agnostic version as well. Let's try using Ignition in a simple Symfony app.

Creating a skeleton Symfony app

This blog post explains that you can create a simple Symfony skeleton application with this commands:

composer create-project symfony/skeleton symfony

This command will create a new Symfony app in the "symfony" directory. I'm using Laravel Valet to serve my sites locally, so I can point my browser to "http://symfony.test" to see the application. Here's how Symfony's default page looks like.

screenshot

A nice touch of this page is that whenever you refresh it, you'll see it in another colour. Nice!

screenshot

Ok, let's not get distracted anymore and try to display the default Symfony error page. Let's put an exception in a random PHP file of that application.

// in bundles.php

throw new Exception("Hello world!");

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
];

You'll now see Symfony's default error page in the browser.

screenshot

Using Ignition

That looks good, but Ignition would look way better. Let's install ignition via composer. That -W flag is needed to let composer upgrade the default dependencies of the Symfony skeleton.

composer require spatie/ignition -W

Now, we're going to register Ignition as early as possible. The public/index.php file is probably the first one that executes. Ignition can be added with just one line of code:

Ignition::make()->register();

Here's the content of the edited file:

<?php

use App\Kernel;
use Spatie\Ignition\Ignition;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

Ignition::make()->register();

return function (array $context) {
    return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};

Let's take a look in the browser now to see Ignition.

screenshot

Beautiful! If you think it's too light, you can activate dark mode (click the cogwheel in the right upper corner to open the preferences).

screenshot

When you scroll down, you see all the details of the request.

screenshot

In closing

Using Ignition in Symfony is pretty straightforward. Granted, I've naively just registered Ignition in the public/index.php file. In Laravel, we're using a service provider for that. Probably there is a cleaner way to do this in Symfony too. If you know the best way to achieve this, let me know in the comments below.

In the Laravel specific version of Ignition, we add extra information on the route used, the logged in user, and more. This is done in the spatie/laravel-ignition package, which builds on the framework agnostic spatie/ignition. It would be awesome to have a symfony-ignition package. Unfortunately, our team doesn't have enough experience to create this. If you want to help create that, let me know!

If you want to know more about Ignition, head over to the readme on GitHub, the introductory blog post, or the streaming session on YouTube.

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

Maru Kari avatar

A good error page not only helps users understand the problem, but also helps developers find Run 3 and fix errors. By investing in building a quality error page, you will improve the user experience and reliability of your application.

Comments powered by Laravel Comments
Want to join the conversation? Log in or create an account to post a comment.