How to Increase or Decrease Laravel Session Lifetime

In this tutorial, you’ll learn how to increase or decrease laravel session lifetime in a Laravel application using two simple methods:

  • By updating the .env file
  • By modifying the config/session.php configuration file

These methods work for all major Laravel versions, including: Laravel 5, Laravel 6, Laravel 7, Laravel 8, Laravel 9, Laravel 10, Laravel 11, and Laravel 12.

What is a Laravel Session?

A session in Laravel is used to store user data across multiple requests. For example, after a user logs in, Laravel uses a session to keep the user authenticated until they log out or the session expires.

How Long Does a Laravel Session Last?

By default, Laravel sessions last 120 minutes (2 hours). However, you can easily change this sessions lifetime to a shorter or longer duration, depending on your app’s requirements.

💡 Note: Laravel sessions are time-based and can’t be set to last “forever”, but you can set a long duration like 1 year (e.g., 525600 minutes).

Laravel Sessions LifeTime Issues

If you change the session lifetime in session.php but it’s not taking effect, make sure:

  • You have set or removed SESSION_LIFETIME in your .env file.
  • You have clear the config cache using the following command:
php artisan config:clear

This ensures your app reads the updated configuration.

How to Set Session Lifetime in Laravel

Method 1: Set Session Lifetime Using .env File

Open your .env file , by default SESSION_LIFETIME is 120 minutes (2 hours).

How to Increase or Decrease Laravel Session Lifetime
.env

You can update this value based on your needs:

Session Lifetime for 1 Year:

    SESSION_LIFETIME=525600  # 1 * 60 * 24
    

    Session Lifetime for 30 minutes :

    SESSION_LIFETIME=30
    

    Method 2: Set Session Lifetime in config/session.php

    Open the file:.env file remove SESSION_LIFETIME variable then next run the command below:

    php artisan cache:clear
    

    Now , Open the file: config/session.php , by default look like this

    How to Increase or Decrease Laravel Session Lifetime
    session.php

    Session Lifetime for 1 Year:

    <?php
    
    use Illuminate\Support\Str;
    
    return [
    
      .....................................................
    
        'lifetime' =>  525600 , # 1 * 60 * 24 * 365
    
       .....................................................
    
    ];