Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 674
igorsantos07 Avatar asked Nov 14 '15 21:11

igorsantos07


People also ask

Where is Laravel config cache?

The cache configuration is located at config/cache. php . In this file you may specify which cache driver you would like used by default throughout your application. Laravel supports popular caching backends like Memcached and Redis out of the box.

Where does php artisan cache clear?

To clear your application cache, you may run the following Artisan command: $ php artisan cache:clear Application cache cleared! This will clear all the cache data in storage which are typically stored in /storage/framework/cache/data/ .

What is memcache in Laravel?

Memcache is a technology that improves the performance and scalability of web apps and mobile app backends. You should consider using Memcache when your pages are loading too slowly or your app is having scalability issues. Even for small sites, Memcache can make page loads snappy and help future-proof your app.

What does php artisan config clear do?

php artisan config:clear Laravel stores all the configuration from App/config directory to a single cached config file at App/bootstrap/cache/config.


1 Answers

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!

like image 95
Felix M Avatar answered Oct 24 '22 14:10

Felix M