Site icon rtCamp

Moving PHP’s session storage to tmpfs

Open php.ini

vim /etc/php5/fpm/php.ini

Add following line.

session.save_path = "/var/run/php5/sessions"

Save and exit.

Run following commands.

mkdir -p /var/run/php5/sessions/
chown -R www-data:www-data /var/run/php5/
cp -rp /var/lib/php5/* /var/run/php5/sessions/
service php5-fpm restart

Edit cron on Debian/Ubuntu

vim /etc/cron.d/php5

Find 2 occurrences of /var/lib/php5/ and replace them with /var/run/php5/sessions/

This cronjob keeps deleting old sessions from time to time. If you forget to do this, you will get disk full error.

That’s it!

Exit mobile version