You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP 7.4.1与Laravel 5.8.38中Session驱动创建不支持问题

Laravel启动报错:Session驱动不支持

错误信息

\vendor\laravel\framework\src\Illuminate\Support\Manager.php:99
Stack trace:
#0 ..\vendor\laravel\framework\src\Illuminate\Support\Manager.php(71): Illuminate\Support\Manager->createDriver('file\r')
#1 ..\vendor\laravel\framework\src\Illuminate\Session\SessionServiceProvider.php(47): Illuminate\Support\Manager->driver()
#2 ..\vendor\laravel\framework\src\Illuminate\Container\Container.php(785): Illuminate\Session\SessionServiceProvider->Illuminate\Session\{closure}(Object(Illuminate\Foundation\Application), Array)
#3 ..\vendor\laravel\framework\src\Illuminate\Container\Container.php(667): Illuminate\Container\Container->build(Object(Closure)) 
#4 ..\vendor\laravel\framework\src\Illuminate\Container\Container.php(615): Illuminate\Container\Container->resolve('session.store', Array)
#5 ..\vendor\laravel\framework\src\Il in ..\vendor\laravel\framework\src\Illuminate\Support\Manager.php on line 99
] not supported. in ..\vendor\laravel\framework\src\Illuminate\Support\Manager.php:99
Stack trace:
#0 ..\vendor\laravel\framework\src\Illuminate\Support\Manager.php(71): Illuminate\Support\Manager->createDriver('file\r')
#1..\vendor\laravel\framework\src\Illuminate\Session\SessionServiceProvider.php(47): Illuminate\Support\Manager->driver()
#2 ..\vendor\laravel\framework\src\Illuminate\Container\Container.php(785): Illuminate\Session\SessionServiceProvider->Illuminate\Session\{closure}(Object(Illuminate\Foundation\Application), Array)
#3 ..\vendor\laravel\framework\src\Illuminate\Container\Container.php(667): Illuminate\Container\Container->build(Object(Closure)) 
#4 ..\vendor\laravel\framework\src\Illuminate\Container\Container.php(615): Illuminate\Container\Container->resolve('session.store', Array)
#5 ..\vendor\laravel\framework\src\Il in ..\vendor\laravel\framework\src\Illuminate\Support\Manager.php on line 99

已尝试清理Composer依赖、清除缓存、复制正常环境的vendor文件夹,问题仍存在。

问题根源

从栈跟踪可见,系统尝试创建名为file\r的Session驱动,其中\r是多余的回车符。说明SESSION_DRIVER配置值混入了隐藏的回车字符,通常由.env文件换行符格式(Windows的CRLF)或复制粘贴时引入冗余字符导致,Laravel解析时将回车符视为驱动名称的一部分,从而判定为不支持的驱动类型。

解决方案

  1. 修复.env文件配置

    • 打开.env文件,找到SESSION_DRIVER项,确保值为file(或你需要的驱动如database),删除配置值前后的空格、回车等隐藏字符。
    • 用支持显示控制字符的编辑器(如VS Code)开启「显示控制字符」功能,确认无多余的\r存在。
    • 将.env文件换行符改为LF(Unix风格),避免Windows系统CRLF换行带来的冗余字符。
  2. 重置配置缓存
    执行命令清除旧缓存并刷新配置:

    php artisan config:clear
    php artisan cache:clear
    

    生产环境可执行php artisan config:cache生成优化后的配置缓存。

  3. 校验session配置文件
    打开config/session.php,确认driver项正确读取环境变量:

    'driver' => env('SESSION_DRIVER', 'file'),
    

    确保无硬编码错误的驱动名称。

内容的提问来源于stack exchange,提问作者Appu Rajendran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 07:35:55