DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
AutoIdle
AutoIdle

Posted on • Originally published at Medium on

Laravel Session configuration on Heroku

Laravel on Herokuβ€Šβ€”β€ŠTip #6

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:

  • Cookie
  • Database
  • Redis

In this example, we use Redis (personally we use always Redis, also for Cache and Queue).

  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. Don’t forget to add the Redis Heroku Addon:
heroku addons:create heroku-redis:hobby-dev
Enter fullscreen mode Exit fullscreen mode
  1. 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 πŸš€

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.

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›