首先确认服务器已经安装redis服务,php安装了redis扩展.
因为我们在laravel的项目中需要下载laravel的redis扩展
~~~
composer require predis/predis
~~~
#### **1.打开config/database.php。在redis配置项中增加session的连接**
~~~
'session' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 10,
],
~~~
![](https://box.kancloud.cn/8961906b94164278c3083309bad895a1_565x431.png)
#### **2.打开config/session.php ,修改driver配置项,将默认的'file'改为'redis';connection配置项填入第一步中配置的redis连接名'session'**
~~~
'driver' => env('SESSION_DRIVER','redis'),
'connection' => 'session',
~~~
![](https://box.kancloud.cn/fed59718ef20f88b2514ac1028d517d7_481x58.png)
![](https://box.kancloud.cn/6ea8f7bf103370f6bbdaae57ef2d2b58_487x62.png)
#### **3.修改.env文件,使用redis存取sessoin**
~~~
SESSION_DRIVER=redis
~~~