jdog
jdog

Reputation: 2539

Symfony session handler default location tries to create directory

I have a Symfony 3.3.5 application for which I want to use the default session handler:

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

However when I do this, Symfony tries to create the /var/lib/php/sessions directory, which already exists:

    [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)"} []

I cannot see why this would be, the directory is world readable, writeable:

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

directory above is not

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 is running as PHP-FPM under its own user name using sockets

Upvotes: 1

Views: 2334

Answers (1)

xsubira
xsubira

Reputation: 532

I had identical symptoms using Apache 2.4 on a CentOS 7, running php-fpm 7.1 by the way of module fast-cgi.

Sessions storage folder was configured to be /var/lib/php/fpm/session, and /var/lib/php/fpm is a remote folder mounted by root user throught NFSv3.
And finally /etc/php-fpm.d/www.conf had following parameters:

user = apache
group = apache

In my case, even having added user apache into php-fpm group, and having settled /var/lib/php/fpm/session permissions as following

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

**In order to mitigate the error reported by Symfony 2.7, it was necessary to force apache user ownership of /var/lib/php/fpm and /var/lib/php/fpm/session this way:

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

Hope it helps

Upvotes: 1

Related Questions