How to Set or Increase Session Lifetime in Laravel?

Last Updated on by in Laravel

How to increase session timeout in laravel 9; well, if you are looking for this solution all over the internet, you are at the right place. In this tutorial, we will explain how you can set laravel session lifetime.

We will share an ideal way through which you can profoundly set the session lifetime in laravel. Whether you are an advanced laravel developer or beginner developer, this ultimate guide will help you extend the laravel development knowledge.

Laravel is a powerful framework that is highly customizable; it comes with handy features that allow dealing with any type of development-related tasks.

As far as session lifetime is concerned, you can increase the session lifetime in laravel by making some adjustments in the session.php file.

It would be best if you look for a lifetime key and set the time in minutes; furthermore, you can go for holistic advancement and may adjust timeout, driver, encrypt and expire on close options.

Set Session Lifetime in ENV File

Ideally, laravel doesn’t allow you to increase session expiration time forever; nevertheless, you may set the session expiration time for several minutes or for the next one year.

60 * 24 * 365 = 525600

You can now take the total minutes, append these minutes in the .env configuration file, and recklessly set the session’s lifetime in laravel.


Set Session Lifetime in Config/Session.php

In this step, we will teach you how to set session lifetime through different method. Open Config/Session.php file and define the SESSION_LIFETIME.

use Illuminate\Support\Str;
return [
    | Session Lifetime
    | Here you may specify the number of minutes that you wish the session
    | to be allowed to remain idle before it expires. If you want them
    | to immediately expire on the browser closing, set that option.

    'lifetime' => env('SESSION_LIFETIME', 120),

So this was it; here are the couple of methods through which you can set session expiration time in laravel.

We hope it will help sharpen knowledge about laravel web development.

Digamber - Author

Hi, I'm Digamber Singh, a New Delhi-based full-stack developer, tech author, and open-source contributor with 10+ years' experience in HTML, CSS, JavaScript, PHP, and WordPress.