Can I safely delete all content in /var/lib/php5?
cd /var/lib/php5
find . -name "sess_*" -print | xargs rm -v
in PHP7
, this worked
cd /var/lib/php/sessions/
sudo find . -name "sess_*" -print |sudo xargs rm -v
If you're using CODEIGNITER
, then try with following commands.
cd /var/lib/php/sessions/
sudo find . -name "ci_*" -print |sudo xargs rm -v
sudo find . -name "cises*" -print |sudo xargs rm -v
Let PHP's gc perform cleanup by itself. Find php.ini and change session.gc_probability
to something bigger, save it and restart Apache (call any php script). It says here http://somethingemporium.com/2007/06/obscure-error-with-php5-on-debian-ubuntu-session-phpini-garbage
In Debian and Ubuntu, /var/lib/php5, where the session data is stored, has permissions of drwx-wx-wt and should only be cleaned by a cron script. So, the package maintainers disable automatic session garbage collection.
Or you could try to put ini_set('session.gc_probability', 100); session_start();
(if your session.gc_divisor
is equal to 100) in one of your scripts and call it. The best way is to put in empty php file, because it might perform cleanup for a very long period of time.
ps: I would also try to leave session.gc_probability
1 and set session.gc_divisor
to 1. It should call gc at every run, but you need it just for a directory cleanup.
And check your cron /etc/cron.d/php5
- it should run every half an hour to purge session files in the /var/lib/php5/ directory.
pps: found interesting comment
This does not disable it (it is commented out). The default within the engine is still used - phpinfo() shows the value to be 1. There is a problem with garbage collection in Debian (and thus Ubuntu) but that's due to PHP wanting to vacuum garbage that has already been removed by the cron script. This causes an error that may be displayed on the unlucky page.