This guide will walk you through adjusting the session timeout duration in your Laravel application. You’ll explore two straightforward techniques:
- Editing the .env file
- 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.
Modify the SESSION_LIFETIME value in your .env file:
SESSION_LIFETIME=525600 # 1 year (60 minutes × 24 hours × 365 days)
For a shorter session, like 30 minutes:
SESSION_LIFETIME=30
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
.....................................................
];
⚠️ 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
Top comments (0)