laravel/laravel
Bootstrap
Active contributors: Taylor Otwell, Nuno Maduro
Purpose
bootstrap/ configures the framework before any request or command runs. Two files matter: app.php builds the Application object, and providers.php lists the application's own service providers. A third subdirectory, bootstrap/cache/, is generated at runtime and is gitignored.
Directory layout
bootstrap/
├── app.php # Fluent configuration of the framework
├── providers.php # Array of App\Providers\* classes to register
└── cache/ # Generated at runtime (config:cache, route:cache, etc.)
└── .gitignore # Excludes everything except itselfbootstrap/app.php
This is the single most important file in the skeleton — it replaces the App\Http\Kernel, App\Console\Kernel, and App\Exceptions\Handler classes that older Laravel versions used.
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware): void {
//
})
->withExceptions(function (Exceptions $exceptions): void {
//
})->create();Each call:
| Step | What it does |
|---|---|
configure(basePath: ...) |
Tells the framework the project root (one level up from this file). |
withRouting(web, commands) |
Registers the route files. Without this, routes/web.php and routes/console.php are not loaded. |
withRouting(health: '/up') |
Registers a GET /up route that returns 200 once the framework is healthy. |
withMiddleware(closure) |
Hook for adding global middleware, route group middleware, or aliases. Currently empty. |
withExceptions(closure) |
Hook for reportable(), renderable(), dontReport(), dontFlash(), etc. Currently empty. |
create() |
Returns the configured Application to be returned from this file. |
When public/index.php does $app = require_once __DIR__.'/../bootstrap/app.php';, it gets exactly this Application.
The Middleware and Exceptions configuration objects
The signatures of the two empty closures are typed against Illuminate\Foundation\Configuration\Middleware and Illuminate\Foundation\Configuration\Exceptions. These are fluent builders provided by the framework. Inside the closures you'd call methods like:
->withMiddleware(function (Middleware $middleware): void {
$middleware->web(append: [
\App\Http\Middleware\TrackPageViews::class,
]);
$middleware->alias([
'subscribed' => \App\Http\Middleware\EnsureSubscribed::class,
]);
})
->withExceptions(function (Exceptions $exceptions): void {
$exceptions->dontReport(\App\Exceptions\IgnorableException::class);
$exceptions->renderable(function (\App\Exceptions\BillingError $e) {
return response()->view('errors.billing', [], 402);
});
})The skeleton ships them empty so a fresh project starts from defaults.
bootstrap/providers.php
return [
AppServiceProvider::class,
];That's the entire file. The framework reads it at boot and registers every listed provider into the service container. Auto-discovered package providers (declared in each Composer package's extra.laravel.providers block) merge with this list automatically.
If you create another provider class — say App\Providers\AuthServiceProvider — you must add its ::class constant to this array. Service providers that aren't listed here and aren't auto-discoverable simply never run.
bootstrap/cache/
The framework writes optimized files into this directory when you run any of:
php artisan config:cache→bootstrap/cache/config.phpphp artisan route:cache→bootstrap/cache/routes-v7.phpphp artisan event:cache→bootstrap/cache/events.phpphp artisan view:cache→ not in this dir, but instorage/framework/views/
The directory ships with a .gitignore that excludes everything except itself, so caches don't get committed.
In production, you generally run php artisan optimize once during deploy. Locally, running composer dev doesn't cache anything — the composer test script even pre-emptively runs php artisan config:clear to make sure stale cached config doesn't poison test runs.
Request and command paths
graph TD
Request[HTTP request] --> Index[public/index.php]
Command[Artisan command] --> Artisan[artisan]
Index --> Bootstrap[bootstrap/app.php]
Artisan --> Bootstrap
Bootstrap --> Configure[Application::configure]
Configure --> WithRouting[withRouting<br/>web/commands/health]
Configure --> WithMiddleware[withMiddleware<br/>empty]
Configure --> WithExceptions[withExceptions<br/>empty]
Configure --> Create[->create]
Create --> App[(Configured Application)]
Create --> Providers[Reads bootstrap/providers.php]
Index --> HandleRequest[handleRequest]
Artisan --> HandleCommand[handleCommand]Integration points
- Routing.
withRouting()is the only place that wiresroutes/web.phpandroutes/console.php. If you add aroutes/api.phpor aroutes/channels.phpyou must register it here. - Service providers.
bootstrap/providers.phpis read alongside the config inwithRouting/withMiddleware/withExceptionsto assemble the boot manifest. - Health check. The
health: '/up'parameter eliminates the need for a custom controller for uptime monitoring.
Entry points for modification
If you need to register a global middleware, customize the priority order, swap the default exception handler, or change error pages, the only file you need to touch is bootstrap/app.php. There is no kernel or handler class to subclass — the closures are the API. For new providers, add their class to bootstrap/providers.php. For everything that is request-time logic, prefer routes and controllers over more bootstrap-level code.
Key source files
| File | Purpose |
|---|---|
bootstrap/app.php |
Builds the Application (routing, middleware, exceptions) |
bootstrap/providers.php |
Lists the application's own service providers |
bootstrap/cache/.gitignore |
Marks the directory tracked but excludes generated cache files |
See App for App\Providers\AppServiceProvider, the only provider this list registers, and Routes for what withRouting() ends up loading.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.