Jose Jimenez
Jose Jimenez
Software Architect & Developer
> >

Optimize Laravel Applications for production

Published in Laravel, PHP on Mar 25, 2022

When deploying a Laravel application always make sure that you are caching and optimizing during your deployment to ensure your application runs as fast and efficiently as possible.

Here are commands that I add as part of every deployment

Laravel Optimization

Optimize will cache Laravel's bootstrap files, while the other two commands will cache events, listeners and compile Blade templates.

1php artisan event:cache
2php artisan view:cache
3php artisan optimize
4 // optimize: will execute the following two commands
5 // php artisan config:cache
6 // php artisan route:cache

Pro Tip: Different packages may have some additional cache optimizations, always check the documentation. As a quick lookup you can run this command to get a dump of commands dealing with cache.

1php artisan | grep cache

Composer Optimization

For composer make sure to optimize your autoloader, more information can be found here.

1composer install --no-dev --optimize-autoloader

For automated deployments you can run

1composer install --no-interaction --no-dev --no-ansi --no-plugins --no-progress --no-scripts --optimize-autoloader