Symfony会话处理程序默认位置尝试创建目录

时间:2017-08-01 21:30:33

标签: php symfony session

我有一个Symfony 3.3.5应用程序,我想使用默认的会话处理程序:

framework:
    session:
        handler_id: session.handler.native_file
        save_path: null

但是当我这样做时,Symfony会尝试创建已存在的/ var / lib / php / sessions目录:

    [2017-08-01 14:24:37] request.CRITICAL: Uncaught PHP Exception RuntimeException: "Session Storage was not able to create directory "/var/lib/php/sessions"" at /home/infoodlebiz/www/site/vendor/symfony/symfony/src/
Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeFileSessionHandler.php line 52 {"exception":"[object] (RuntimeException(code: 0): Session Storage was not able to create directory \"/var/lib/php/sessions\" at /home/infoodlebiz/www/site/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeFileSessionHandler.php:52)"} []

我不明白为什么会这样,该目录是世界可读的,可写的:

ls -la /var/lib/php/sessions/
total 176
drwx-wx-wt 2 root       root       110592 Aug  1 14:28 .
drwxr-xr-x 4 root       root         4096 Oct 16  2016 ..
-rw------- 1 globalyear globalyear    305 Aug  1 14:04 sess_1u179qdaqcihhkmmi4qepj2na0
-rw------- 1 globalyear globalyear    305 Aug  1 14:15 sess_5p76n0falmf0rmogs4v2s9sss5
-rw------- 1 globalyear globalyear    304 Aug  1 13:49 sess_65i7jlca6ifhs8k1ucdkf8d091
-rw------- 1 cbc        cbc           213 Aug  1 14:28 sess_9hfobt8p6lu056avq2udiq7ck0
-rw------- 1 cbc        cbc           213 Aug  1 14:06 sess_b6mdvgj6v6ip1l1pi77upnc845
上面的

目录不是

ls -la /var/lib/php/
total 124
drwxr-xr-x  4 root root   4096 Oct 16  2016 .
drwxr-xr-x 49 root root   4096 Mar 29 13:39 ..
drwxr-xr-x  3 root root   4096 Oct 16  2016 modules
drwx-wx-wt  2 root root 110592 Aug  1 15:25 sessions

PHP使用套接字

在其自己的用户名下作为PHP-FPM运行

1 个答案:

答案 0 :(得分:1)

我在 CentOS 7 上使用 Apache 2.4 ,通过模块快速运行 php-fpm 7.1 时出现了相同的症状-cgi

会话存储文件夹配置为/var/lib/php/fpm/session/var/lib/php/fpmroot用户通过 NFSv3 安装的远程文件夹。
最后/etc/php-fpm.d/www.conf有以下参数:

user = apache
group = apache

就我而言,即使已将用户apache添加到php-fpm群组中,并已将/var/lib/php/fpm/session权限解除如下

$ ls -lad /var/lib/php/fpm/session
drwxrwx--- 2 root php-fpm 487 dic  4 11:54 /var/lib/php/fpm/session

**为了缓解 Symfony 2.7 报告的错误,有必要强制 apache 用户拥有/var/lib/php/fpm/var/lib/php/fpm/session这样:

chown apache /var/lib/php/fpm 
chown apache /var/lib/php/fpm/session

希望有所帮助