When deploying your Laravel Application, I’m sure you want to fine tune as much as possible to make it as performant as it can be. The community offers many tools to help you in development like the debugbar and production packages like HTTP/2 Server Push.
Outside of these, Laravel also offers core features to help speed up your application and one of those is configuration caching Artisan command:
php artisan config:cache
This will combine all of the configuration options into one single file which will be loaded quicker by the framework, and this bypasses the
env helper for looking up config items through the dotenv package, so you will need to ensure you are not using this anywhere outside of your config files.
Instead of using
env you can and should instead use something like the config helper. As an example:
// Change this in your app code: env('BUGSNAG_API_KEY'); // To something like this: config('services.bugsnag.key');
Once you run the
config:cache command two new files will be generated in app/bootstrap/cache/ folder. These are config.php and services.php and you can look through those to see exactly how it’s compiled down.
Of course, this command is not without some caveats. You should only run this in production because environmental values are designed to change during local development and each developers machine. Secondly, this should be setup so that on deploy the cache is rebuilt, so you are getting new changes each time.