Skip to main content
All posts
· 5 min read

Laravel bootstrap/cache Files Explained: Safe to Delete?

What config.php, packages.php, services.php and routes-v7.php in Laravel's bootstrap/cache are, which command makes each, and whether it is safe to delete them.

If you have deployed a Laravel app, you have seen the files in bootstrap/cache/ and wondered what they actually are. config.php, packages.php, services.php, routes-v7.php. They look like the kind of files that should be in vendor/ or somewhere a script manages, not sitting next to your source.

They are compiled caches. Laravel writes them so it can load config, routes, and package discovery results from a single PHP file instead of parsing dozens of files and re-running discovery on every request. Understanding what each one does, and when it gets written, helps you avoid the classic deploy problems: stale config, missing routes, and workers running old code.

What each file is

config.php

Created by php artisan config:cache. Laravel loads every file in config/, evaluates the environment values, and writes the result to bootstrap/cache/config.php as one PHP array. Once the file exists, calls like config('database.default') read from it directly.

This is why the Laravel docs warn against using env() outside config files. After config:cache runs, env() reads from the cached array in production, not from .env. If a job or custom class calls env('REDIS_HOST'), it can behave differently from config('database.redis.default.host').

packages.php and services.php

Created during package discovery, which Laravel runs when you install dependencies or run php artisan package:discover (also part of optimize). The framework scans the installed packages, finds their service providers and bootstrappers, and writes the results to packages.php and services.php.

You usually do not think about these files because Composer triggers discovery automatically after installs. But if they are missing or stale, packages fail to register their providers and parts of your app quietly stop loading.

routes-v7.php

Created by php artisan route:cache. Laravel compiles every route definition into bootstrap/cache/routes-v7.php. The v7 in the name tracks the route cache format, not your Laravel version directly, which is why you may also see routes-v8.php on newer releases.

Route caching gives a real speedup on large apps, but it has a known trap: closures in routes cannot be cached. If any route uses a closure, route:cache fails and your deploy script fails with it.

Should you commit them to git?

No. The standard Laravel .gitignore already contains bootstrap/cache/*.php, which covers all four files. If you see them in git status, either the ignore rule is missing or someone force-added them. They are environment-specific compiled output: fast to regenerate, and wrong to share between machines.

What should be committed is bootstrap/cache/.gitignore, the file that contains the rule. Keep it, and never commit the *.php files it excludes.

Is it safe to delete them?

Yes, in the sense that Laravel can rebuild every one of them. Nothing in them is your data. What changes is what the app does until they are rebuilt:

FileRebuilt byIf it is missing
config.phpphp artisan config:cacheLaravel reads config/ and .env directly on each request. Slower, but correct.
routes-v7.phpphp artisan route:cacheLaravel loads your route files directly. Slower, but correct.
packages.phpphp artisan package:discoverLaravel rebuilds it on the next boot.
services.phpWritten automatically on bootLaravel rebuilds it on the next boot.

To clear them the supported way, run php artisan optimize:clear, or config:clear and route:clear for just those two. Deleting the files by hand does the same thing.

Two things to leave alone. Keep the bootstrap/cache/ directory and its .gitignore, and keep it writable by the web user: Laravel stops with a “bootstrap/cache directory must be present and writable” error otherwise. And do not clear the caches in the middle of a release on a live host without rebuilding right after, because the app then runs uncached until you do.

Where deploy problems come from

The files are usually fine. The problems start when the commands that create them run at the wrong time in a deploy.

config:cache must run after the new .env and config files exist, and it has to run on every server that serves traffic. If the hook runs in the old release directory, or one host fails while the others succeed, production keeps pointing at the previous settings. Same story with route:cache: a closure in a route makes the command fail, and if the rest of the deploy does not stop, you ship with the old route file.

When these caches go stale, the failures are intermittent and confusing: mail points at the old SMTP server, the payment gateway uses the previous key, some hosts return 404 for routes that exist in code. Nothing crashes loudly, because the app boots fine and serves cached versions of the old truth.

Teams that have been burned by this tend to add a check that runs after deploy: verify the new release directory is live, confirm config.php and routes-v7.php were regenerated, and confirm every host agrees on the same values. That is exactly the kind of thing cron and queue monitoring tools like Crontinel watch externally, so the moment a deploy hook fails or a server keeps stale config, you get an alert instead of finding out from user reports. If you want the deeper setup, the monitoring config:cache guide walks through the full ping strategy.

If you are debugging a fleet-wide config mismatch right now, start with php artisan config:clear and php artisan route:clear on one host, rebuild both caches, and compare the files across hosts. The file that differs tells you which server ran a different deploy sequence.

The short version

bootstrap/cache holds compiled config, package discovery results, and routes. Laravel regenerates them with config:cache, package:discover, and route:cache. Do not commit them, do not delete them mid-deploy, and make sure the commands that build them run after every release, on every host.

See also

use cases
How to Monitor php artisan optimize in Production

Monitor Laravel's optimize command in production so you catch config cache failures, route cache problems, and bootstrap errors before they break deploys.

use cases
routes-v7.php Explained: Laravel Route Cache Monitoring

What is bootstrap/cache/routes-v7.php? Learn how route:cache creates it, what breaks during rolling deploys, and how to get alerted when it is stale.

use cases
Monitoring config:cache in Laravel Production

Watch Laravel's config:cache command in production so stale environment values, broken config files, and missed deploy hooks do not quietly break your app.

use cases
How to Monitor php artisan optimize:clear After Deployment

Make php artisan optimize:clear visible after Laravel deployments so stale config, route, view, and event cache problems do not survive unnoticed.

use cases
Monitoring config:clear in Laravel Production

Watch Laravel's config:clear command in production so an accidentally cleared config cache, a failed rebuild, or a half-finished deploy step gets caught.

blog
Detecting Laravel Broadcast Failures Before Users Do

Broadcasting silently fails in production: Pusher disconnects, Reverb drops, Soketi restarts. Detect broadcast failures and monitor WebSocket health.