ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13)
When running PHP5 under Ubuntu, every ~100 times you call session_start() the following error is thrown:
ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) in ...
By default, session data is stored in /var/lib/php5 which has its permissions set to only allow data to be deleted by it’s owner (and root). It’s like this because there is a cron script that periodically clears the session data. To prevent PHP from also trying to do this, switch off the session garbage collection in php.ini (/etc/php5/apache2/php.ini) with the following:
session.gc_probability = 0It is quite likely to be set to 1 by default. Save changes and restart apache.
sudo /etc/init.d/apache2 restart
This entry was posted on Thursday, September 9th, 2010 at 3:35 pm and is filed under GNU Linux, PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

October 11th, 2010 at 7:03 pm
Thanks.
October 21st, 2010 at 11:36 am
Thanks, saved me time figuring what this random message means. session.gc_probability = 0 makes the garbage collector running 0 of 100 times. But is the result not that ‘garbage’ keeps pilling up? And what are the consequences of that?
October 21st, 2010 at 11:41 am
No, as far as I understand it, Ubuntu is configured to go in there and clear the ‘garbage’ via a cron script.
November 12th, 2010 at 8:28 am
Thanks, it saved me a lot of time.
January 13th, 2011 at 6:35 am
Thanks, it worked for me also!
March 12th, 2011 at 7:18 pm
Thanks a lot!
This is something that happens under Ubuntu, Debian php5 package hasn’t that problem (instead has others, but that are off-topic in this post :p)
For the record:
Debian Lenny:
————-
; This is disabled in the Debian packages, due to the strict permissions
; on /var/lib/php5. Instead of setting this here, see the cronjob at
; /etc/cron.d/php5, which uses the session.gc_maxlifetime setting below.
; php scripts using their own session.save_path should make sure garbage
; collection is enabled by setting session.gc_probability
;session.gc_probability = 0
session.gc_divisor = 100
Debian Squeeze:
—————
; Defines the probability that the ‘garbage collection’ process is started
; on every session initialization. The probability is calculated by using
; gc_probability/gc_divisor. Where session.gc_probability is the numerator
; and gc_divisor is the denominator in the equation. Setting this value to 1
; when the session.gc_divisor value is 100 will give you approximately a 1% chance
; the gc will run on any give request.
; Default Value: 1
; Development Value: 1
; Production Value: 1
; http://php.net/session.gc-probability
session.gc_probability = 0
Ubuntu Maverick Meerkat:
————————
; Defines the probability that the ‘garbage collection’ process is started
; on every session initialization. The probability is calculated by using
; gc_probability/gc_divisor. Where session.gc_probability is the numerator
; and gc_divisor is the denominator in the equation. Setting this value to 1
; when the session.gc_divisor value is 100 will give you approximately a 1% chance
; the gc will run on any give request.
; Default Value: 1
; Development Value: 1
; Production Value: 1
; http://php.net/session.gc-probability
session.gc_probability = 1
July 5th, 2011 at 5:29 pm
Craft It Online! » Permissions Problems with Symfony2: Another Tip says:[...] http://www.kriswillis.com/index.php/2010/09/09/ps_files_cleanup_dir-opendirvarlibphp5-failed-permiss... Tweet Posted on July 5, 2011 by Luis Cordova. This entry was posted in Development, symfony. Bookmark the permalink. « Set Default/Custom Selection in Symfony2 Forms [...]