kernel.php in Laravel 12: Where is it?

laravel
middleware
console
tutorial
Nabil Hassen
Nabil Hassen
Jul 29, 2025
How to replace kernel.php files in Laravel 11+ (and 12)
Last updated on Oct 17, 2025
Table of contents:

Replacing Kernel Files in Laravel 11 and Later Versions

In Laravel 11 and later, the traditional App\Http\Kernel and App\Console\Kernel classes have been removed. Instead, their responsibilities have been moved to the bootstrap/app.php file using a new, simplified and centralized configuration approach.

This post walks you through how to migrate your middleware and console scheduling logic from the old Kernel classes to the new Laravel 11 and later structure.

HTTP Kernel Changes: Middleware Configuration

Previously, your middleware setup was done in App\Http\Kernel. You had to manage three major arrays:

  • $middleware: global middleware
  • $middlewareGroups: group middleware for web, api, etc.
  • $middlewareAliases: route middleware aliases

In Laravel 11, all of this now goes into a closure inside bootstrap/app.php, using the withMiddleware() method:

->withMiddleware(function (Middleware $middleware) {
// Global middleware
$middleware->append(EnsureTokenIsValid::class);
 
// Middleware groups
$middleware->appendToGroup('group-name', [
First::class,
Second::class,
]);
 
$middleware->prependToGroup('group-name', [
First::class,
Second::class,
]);
 
// Middleware aliases
$middleware->alias([
'subscribed' => EnsureUserIsSubscribed::class
]);
})

Console Kernel Changes: Scheduling and Commands

Before Laravel 11, command scheduling was defined in the App\Console\Kernel class, particularly in the schedule() and commands() methods.

Now, both your scheduled tasks and command routes are defined in routes/console.php, like this:

use Illuminate\Console\Scheduling\Schedule;
 
Schedule::command('inspire')->hourly();

There is no need to explicitly register these commands in a Kernel class as Laravel will automatically load them from the routes/console.php file, as long as you include the file via withRouting() in bootstrap/app.php:

->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)

By default, Laravel automatically registers all commands in app/Console/Commands. To register commands from other directories or manually specify commands, use the withCommands method in bootstrap/app.php:

->withCommands([
__DIR__.'/../app/Domain/Orders/Commands', // Scan directory
\App\Domain\Orders\Commands\SendEmails::class, // Or register specific classes
])

When Artisan boots, it resolves and registers these commands automatically.

Final bootstrap/app.php Example

Here’s how a complete bootstrap/app.php file may look in Laravel 11 and later:

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
 
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
// Configure middleware here (see full example above)
})
->withCommands([
// __DIR__.'/../app/Domain/Orders/Commands',
// \App\Console\Commands\Inspire::class,
])
->withExceptions(function (Exceptions $exceptions) {
// Handle exceptions here
})
->create();

kernel.php: Before vs After

Before (Laravel 10 and Earlier)

// app/Http/Kernel.php
class Kernel extends HttpKernel
{
protected $middleware = [
\App\Http\Middleware\EnsureTokenIsValid::class,
];
 
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
],
];
 
protected $middlewareAliases = [
'subscribed' => \App\Http\Middleware\EnsureUserIsSubscribed::class,
];
}
 
// app/Console/Kernel.php
class Kernel extends ConsoleKernel
{
protected function schedule(Schedule $schedule): void
{
$schedule->command('inspire')->hourly();
}
 
protected function commands(): void
{
$this->load(__DIR__.'/Commands');
}
}

After (Laravel 11 and 12)

// bootstrap/app.php
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Schedule;
 
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->append(\App\Http\Middleware\EnsureTokenIsValid::class);
 
$middleware->alias([
'subscribed' => \App\Http\Middleware\EnsureUserIsSubscribed::class,
]);
})
->withCommands([
__DIR__.'/../app/Console/Commands',
])
->create();
 
// routes/console.php
Schedule::command('inspire')->hourly();

Conclusion

Laravel 11 simplified application bootstrapping by consolidating the Kernel logic into bootstrap/app.php. This modern approach reduces boilerplate and keeps configuration centralized, making your app more maintainable and transparent.

Nabil Hassen
Nabil Hassen
Full Stack Web Developer

Stay Updated.

I'll you email you as soon as new, fresh content is published.

Thanks for subscribing to my blog.

Latest Posts