DEV Community

AutoIdle
AutoIdle

Posted on • Originally published at Medium on

2 2

Laravel Deployment Optimization on Heroku

Laravel on Heroku — Tip #4

Photo by Todd Quackenbush on Unsplash

Laravel has great documentation about deployment.

The most important part is optimization, which includes 3 parts:

  1. Autoloader Optimization
  2. Optimizing Configuration Loading
  3. 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
 ]
}
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay