How To Increase Session Lifetime In Laravel

Websolutionstuff | Jun-28-2020 | Categories : Laravel PHP

In this article, we will see how to increase session timeout in laravel. In this example, we can see how to set session lifetime in laravel. We can not set lifetime sessions permanently but we can set in minutes for the session expiration time.

So, let's see laravel set session expiration and how to set session timeout in laravel 6 and laravel 7, and how to set session lifetime in laravel.

So, here we will set 1 year time for the session to expire.

60 * 24 * 365 = 525600 // 1 year

If you want to increase your session lifetime then we need to change it in the .env file and it is very easy to change it from the configuration file in laravel. laravel provides you a session.php file there we can see the 'lifetime' key option for setting time in minutes. In the session configuration file there is an also several options for set expire_on_close, encrypt, timeout and driver, etc.



Here, we will give you two solutions for increasing session timeout in laravel.

Solution 1: Using .env File

We need to define the value in minutes in your env file as below.



use Illuminate\Support\Str;
return [

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



Solution 2: Using Config File


use Illuminate\Support\Str;
return [
    'lifetime' => 1 * (60 * 24 * 365),

In some conditions also happen Cache issue, So, we need to clear it.

For clearing Cache, View, and Routes in Laravel check below.

And, Now your session timeout time will be increased.


You might also like:

Recommended Post
Featured Post
Laravel 9 Two Factor Authentication Using Email
Laravel 9 Two Factor Authentic...

In this article, we will see laravel 9 two-factor authentication using email. Here, we will send the OTP code to em...

Read More


How To Disable Dates After Week In jQuery Datepicker
How To Disable Dates After Wee...

In this tutorial, we will see how to disable dates after a week in jquery datepicker. In the date picker, we can di...

Read More


How To Validate International Phone Number Using jQuery
How To Validate International...

In this article, we will see how to validate international phone numbers using jquery. Here, we will learn about mo...

Read More


How to Image Upload with Preview in Angular 17
How to Image Upload with Previ...

In this article, we'll see how to image upload with a preview in angular 17. Here, we'll learn about the an...

Read More