Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
20
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

Laravel 5.3でセッション管理にredisを使用する方法

参照

設定方法

predis/predisパッケージをインストール

  • コンソールで下記を実行

    cd /your/project/path
    composer require predis/predis
    

redisサーバの設定を追加

  • config/database.phpの「Redis Databases」の情報を変更。
  • 実際には下記のようになっているので、.env.xxxxxファイルを変更。

    config/database.php
        /*
        |--------------------------------------------------------------------------
        | Redis Databases
        |--------------------------------------------------------------------------
        |
        | Redis is an open source, fast, and advanced key-value store that also
        | provides a richer set of commands than a typical key-value systems
        | such as APC or Memcached. Laravel makes it easy to dig right in.
        |
        */
    
        'redis'       => [
    
            'cluster' => false,
    
            'default' => [
                'host'     => env('REDIS_HOST', 'localhost'),
                'password' => env('REDIS_PASSWORD', null),
                'port'     => env('REDIS_PORT', 6379),
                'database' => 0,
            ],
    
        ],
    
  • .env.xxxxxを編集。

    env.xxxxx
    REDIS_HOST=(your_redis_host)
    REDIS_PASSWORD=(your_redis_password)
    REDIS_PORT=6379
    

セッションドライバーの変更

  • config/sessions.phpの「Default Session Driver」を変更
  • 実際には下記のようになっているので、.envファイルを変更。

    config/sessions.php
        /*
        |--------------------------------------------------------------------------
        | Default Session Driver
        |--------------------------------------------------------------------------
        |
        | This option controls the default session "driver" that will be used on
        | requests. By default, we will use the lightweight native driver but
        | you may specify any of the other wonderful drivers provided here.
        |
        | Supported: "file", "cookie", "database", "apc",
        |            "memcached", "redis", "array"
        |
        */
    
        'driver'          => env('SESSION_DRIVER', 'file'),
    
    
  • .env.xxxxxを編集。

    env.xxxxx
    SESSION_DRIVER=redis
    

余談

  • AP<->DB構成の場合、こんなことでハマってしまった…。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
20
Help us understand the problem. What are the problem?