I have a CentOS 6 box running nginx and PHP 7.2.
My php 7.2 session files exist where I expect them to, in
/var/opt/remi/php72/lib/php/session
However, I've just noticed that a smaller number of them exist in
/tmp
I only have one version of php installed, running a number of sites. phpInfo();
reports the first directory for each site. I can't find any reference to /tmp
regarding sessions at all.
I have discovered that if I run php -r 'phpInfo();' | grep save_path
I get session.save_path => no value => no value
, so I guess that's causing it? I.e. my cron jobs are creating the empty session files.
Is this normal? If so, why? Why does php run from the command line not use the value set in php.ini?
Thanks
Best Answer
Yes.
This is documented in the configuration file. Each user must have a different location to avoid access issues.
So the path is configured in each SAPI file
Default to
/tmp
(for CLI users)See these comments in your php.ini:
It means that
/var/opt/remi/php72/lib/php/session
is only used by theapache
user (the default user in the FPM pools of your distribution).And if you use multiple FPM pools, running with different users, you have to set a different location for each, see
php-fpm.d/www.conf
: