PHP’s ps_file_cleanup_dir Error

One of the most annoying errors you can get is the session_start(): ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) error.  It’s one of those where, as a developer, you instinctively press F5 and then you don’t get it for ages.  This is caused by the Apache/HTTPD linux user not having the permissions to cleanup old session files, stored in /var/lib/php5.

There are two ways of solving this problem:

1) Grant permissions to the webserver

To do this, you will need root SSH access.  Simply enter the following command:

chmod 777 /var/lib/php5

2) Disable session cleanup

If you don’t have root SSH access, you can write the following line BEFORE the session_start() function.

ini_set('session.gc_probability', 0);

The cleanup function works on a probability of activation.  It’s actually calculated from dividing the session.gc_probability by the session.gc_divisor.

You can do this in the PHP.ini file too.  One word on disabling the session cleanup – I don’t see it as a great problem, but I wouldn’t do it on productions servers if you can avoid it – it’s there for a reason after all…

Leave a Reply