PHP Sessions not being deleted on Ubuntu Server

Website

I came across an issue on one of our Ubuntu 10.04 servers where there was over 1GB of session files, and none getting deleted. I didn't know that Ubuntu ignores the normal PHP method for deletion in favour of using cron.

I won't re-write the whole shebang here, but here is the article that shed some light on the situation for me:

  • http://www.laurencegellert.com/2012/08/php-sessions-not-being-deleted-on-ubuntu-server/

Here's what I did:

1. Make a backup: 

cp /usr/lib/php5/maxlifetime /usr/lib/php5/maxlifetime.bak

2. Edit maxlifetime file

nano /usr/lib/php5/maxlifetime

3. I deleted everything and pasted this:

#!/bin/sh -e

max=1440

echo$(($max/60))

exit 0