How to cache configuration in Laravel inside Heroku? those. build another path from the runtime

In Laravel docs, we recommend running ./artisan config:cache in production to speed ./artisan config:cache up. This is good with Heroku, since each build creates a new state for the file system, so we don’t even have to worry about clearing the cache between deployments.

BUT: if you add this command to your deployment procedure (for example, through Composer), your Laravel application will crash because it will look for files in existing build paths (something like /tmp/random_string ). If you run heroku run pwd , you will notice that the runtime is running on /app .

It seems that ./artisan config:cache stores the temporary build path in cached settings, and the application runs in a different path. Is it possible to change the path used in the resulting configuration cache?

+6
source share
1 answer

This is best done at boot time and not during build. To do this, you need to modify the .json composer to add:

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

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

Credits for clues go to David from Heroku support!

+3
source

All Articles