How to fix the «Notice: SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied» issue?

Hi,

This is causing some permission issues since it tries to clear sessions stored in /var/lib/php/sessions - may I ask why it’s turned on and is it ok for me to turn it off?

Getting these errors sporadically:

1 exception(s):
Exception #0 (Exception): Notice: SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied (13) in /var/www/magento/vendor/magento/framework/Session/SaveHandler.php on line 129

Exception #0 (Exception): Notice: SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied (13) in /var/www/magento/vendor/magento/framework/Session/SaveHandler.php on line 129
#0 [internal fu

For fixing the «Notice: SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied» issue I recommend to grant the write access rights for this particular folder (/var/lib/php/sessions) to the operating system account you use for the PHP interpreter.

Another good solution is to set a custom location (which the PHP interpreter can write the session files to) for the session folder with the session.save-path PHP option:

Disabling the PHP’s session garbage collector with the session.gc_probability=0 PHP setting is not a good solution, because you will have a lot of orphaned session files in the session folder, and it will waste the disk space and slow down your server.

1 Like

I have added an improvement to the 2.6.10 version of my mage2pro/core, and it should automatically fix such issues.