Laravel by default will save sessions into a directory on disk, which isn’t ideal, because Heroku uses an ephemeral filesystem (explained in Tip #5).
You have to use another session driver. Laravel ships with several great drivers out of the box:
In this example, we use Redis (personally we use always Redis, also for Cache and Queue).
- You have to change the default session driver to Redis in config/session.php:
or by setting the SESSION_DRIVER environment variable:
heroku config:set SESSION\_DRIVER=redis
- Don’t forget to add the Redis Heroku Addon:
heroku addons:create heroku-redis:hobby-dev
- Use our Tip #1 to use Heroku environment variables in your Laravel app.
That’s it, now your session will not expire again after restart or deploy 🚀