How to Increase or Decrease Laravel Session Lifetime
itstuffsolutions

itstuffsolutions @itstuffsolutions

About: itstuffsolutions.io offers easy-to-follow IT and programming tutorials, tips, and solutions to help developers and tech enthusiasts learn and solve real-world problems effectively.

Joined:
May 29, 2025

How to Increase or Decrease Laravel Session Lifetime

Publish Date: Jun 23
2 0

This guide will walk you through adjusting the session timeout duration in your Laravel application. You’ll explore two straightforward techniques:

  1. Editing the .env file
  2. Editing the config/session.php configuration file

Both approaches are compatible with all major Laravel versions — from Laravel 5 up to Laravel 12.

What is a Laravel Session?

A Laravel session is a way for your web application to remember information about a user across multiple page visits.

Think of it like this: When someone visits your website and logs in, the session acts like a temporary memory that stores key details — like their user ID or login status — so they don’t have to log in again every time they visit a new page.

Laravel handles this automatically behind the scenes. It gives each visitor a ** unique session** ID (usually stored in a browser cookie), and stores the data either in files, a database, or another storage system — depending on how your app is set up.

Method 1: Editing the .env file

Open your .env file , by default SESSION_LIFETIME *is **120 minutes *, which means user sessions will expire after **2 hours of inactivity.

Image description

Modify the SESSION_LIFETIME value in your .env file:

SESSION_LIFETIME=525600   # 1 year (60 minutes × 24 hours × 365 days)

Enter fullscreen mode Exit fullscreen mode

For a shorter session, like 30 minutes:

SESSION_LIFETIME=30
Enter fullscreen mode Exit fullscreen mode

Laravel will automatically use this value to control how long a session remains active.

Method 1: Editing the config/session.php configuration file

open, the session.php ,Alternatively, you can define the session lifetime directly in the config/session.php file:

<?php

use Illuminate\Support\Str;

return [

  .....................................................

    'lifetime' =>  525600 , # 1 * 60 * 24 * 365

   .....................................................

]; 
Enter fullscreen mode Exit fullscreen mode

⚠️ Important: Changes in session.php Not Taking Effect?

If you've updated the session lifetime in config/session.php but it's not reflecting in your application, make sure to:

👉 Want the full code and detailed explanation? Check out the complete step-by-step guide on my blog: Read Full Tutorial Here

Comments 0 total

    Add comment