Laravel on Heroku — Tip #4
Laravel has great documentation about deployment.
The most important part is optimization, which includes 3 parts:
- Autoloader Optimization
- Optimizing Configuration Loading
- Optimizing Route Loading
On Heroku, we also need these 3 optimizations.
Autoloader Optimization
We have to optimize Composer’s class autoloader with the following command:
composer install --optimize-autoloader --no-dev
Heroku already run composer install with this command (Doc). Thanks Heroku 👍
️Optimizing Configuration Loading and Route Loading
We should run
php artisan config:cache
php artisan route:cache
for optimizing configuration loading and route.
We will call these 2 artisan commands on boot so we create a new scripts entry in composer.json, e.g. warmup:
"scripts": {
"warmup": [
"php artisan config:cache",
"php artisan route:cache"
]
}
You may then combine invocation of that script together with your existing command in Procfile, for example:
web: composer warmup && $(composer config bin-dir)/heroku-php-apache2 web/
That's it, our Laravel app on Heroku is optimized! 🚀
Want more tips like these?
You should follow me on Twitter! And if you’re building on Heroku, you should check out AutoIdle — the automated way to save money on your staging and review apps.
Top comments (0)