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.

php artisan event:cache
php artisan view:cache
php artisan optimize
 // optimize: will execute the following two commands
 // php artisan config:cache
 // 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.

php artisan | grep cache

Composer Optimization

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

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

For automated deployments you can run

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