Zend_Session / Zend_Auth randomly throws Error Message ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13)

Apparently this issue is affecting mostly (only?) debian/ubuntu based systems and has to do with automatic session garbage collection.

The variable session.gc_probability was set to 1 in the php.ini which means there is a 1% probability for the garbage collector to run and clean up the directory /var/lib/php5 where the php sessions are stored.

Apparently this folder is not writable by www-data resulting in the mentioned error and throwing the Zend exception. Setting session.gc_probability to 0 solved the problem. The session folder is cleaned up by a cron job anyway, so no need for the php garbage collector to even run.

From http://somethingemporium.com/2007/06/obscure-error-with-php5-on-debian-ubuntu-session-phpini-garbage


A solution is to set the session.save_path in the php.ini file to a writable directory. for example: session.save_path = "/tmp". Switching the session garbage collection off in the first example is not a good idea. The second example does not work on Ubuntu 10.04


Actually changing the directory of the session.save_path turns garbage collection off. That is why it now works for you. If you want garbage collection you can change the original directory owner to the php user "www-data"

chown www-data /var/lib/php5

In the alternative you can write a garbage collection script for the new directory.