11
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel7でセッションタイムアウト時間を変更する

Last updated at Posted at 2021-07-05

前置き

セッションタイムアウトに関する処理を行う際に時間変更する方法を調べたため、自分用に残します。

前提条件

Laravel 7
php 7.4

結論

調べた際に以下の2つの方法がありました。

方法①:.envファイルのSESSION_LIFETIMEの値を変更する

.envファイルの真ん中あたりに書いてあるSESSION_LIFETIME=120の値を任意の値に変更する。
(デフォルトでは120になっているため、変更しない場合は2時間でセッションタイムアウトになります。)

SESSION_LIFETIME=任意の数値

変更後に以下のコマンドを実行する。
※キャッシュ系のコマンドであるため、要確認を行うこと

php artisan config:cache

方法②:config/session.phpファイルの'lifetime'を変更する

config/session.phpファイルに記載されている'lifetime' => env('SESSION_LIFETIME', 120)を任意の値に変更する。
(デフォルトでは120になっているため、変更しない場合は2時間でセッションタイムアウトになります。)

config/session.php
'lifetime' => env('SESSION_LIFETIME', 任意の値)

変更後は、方法①と同様にphp artisan config:cacheを実行する。

参考・引用元

大変参考にさせていただきました。ありがとうございます。
https://teratail.com/questions/254235

11
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?