Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

参照

設定方法

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構成の場合、こんなことでハマってしまった…。
LowSE01
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした