igorsantos07
igorsantos07

Reputation: 4686

How to cache configuration in Laravel inside Heroku? i.e. build in a different path from runtime

In the Laravel docs it's advised to run ./artisan config:cache in production to speed things up. That's great with Heroku since every build brings up a new filesystem state, so we don't even have to bother with clearing the cache between deploys.

BUT: if you add that command to your deployment procedure (via Composer for instance) your Laravel app will start crashing, since it'll be looking for files in the now-gone build paths (something like /tmp/random_string). If you run heroku run pwd you'll notice the runtime app lives on /app.

It seems ./artisan config:cache stores the temporary build path in the cached settings, while the app runs in another path. Is it possible to change the path used in the resulting config cache?

Upvotes: 8

Views: 2544

Answers (1)

Felix M
Felix M

Reputation: 305

You'd best do this at boot and not at build time. In order to do so you need to modify you composer.json to add:

"warmup": [
    "php artisan config:cache",
    "php artisan route:cache"
],

And then modify your procfile to something like web: composer warmup && $(composer config bin-dir)/heroku-php-apache2 public/

Credits for the tip goes to David from the Heroku support!

Upvotes: 14

Related Questions