Optimize Laravel Applications for production
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.
Copied!
1php artisan event:cache2php artisan view:cache3php artisan optimize4 // optimize: will execute the following two commands5 // php artisan config:cache6 // 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
.
Copied!
1php artisan | grep cache
Composer Optimization
For composer make sure to optimize your autoloader
, more information can be found here.
Copied!
1composer install --no-dev --optimize-autoloader
For automated deployments you can run
Copied!
1composer install --no-interaction --no-dev --no-ansi --no-plugins --no-progress --no-scripts --optimize-autoloader