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!
any measurable effect of doing this?
I did not measured so cannot count. I am trying to move as much temporary data to tmpfs as possible.
I’m having a problem and I think it is related to this. What ownership and permissions does /var/run/php5/sessions/ need?
a chown -R www-data:www-data /var/run/php5/sessions followed by chmod -R 755 /var/run/php5/sessions fixed my problem but not sure its the proper solution?
Thanks for sharing your solution.
I used
cp -rp
on live server. So I might have missed that issue. Anyway, updated article to take care of permission issue.Ah, I don’t usually copy/paste very step, so I guess I overlooked the cp -rp and got into trouble when the session storage could not be written to 🙂
No. No. I added
cp -rp
after your comment. Earlier it wascp -r
only. 🙂Oh, btw. is /var/run/ automatically mounted on tmpfs? Is this a newer development? Is the whole /var folder on tmpfs? only run? What about /var/cache?
Sorry to bug you with these questions but it seems you know more about these folders than me 🙂
You can find that always using
mount
command./var/run
is symlink to/run
and/run
is mounted on tmpfs. Atleast in Ubuntu 12.04.hm, on Debian Wheezy it looks like this:
so it doesn’t look like it. You see the two tmpfs mounts on /var/cache – I manually added those. Maybe I should add a similar one for the session cache?
You can do either way.
Or just run
ls -l /var/run
to check if its a real dir or symlink.I’m a bit confused. I tried that but
ls -al /var/run
simply lists the content of the folder, as doesls -al /var/cache/nginx
which is definitely mounted on tmpfs.Am I doing something wrong or misreading the results?
ls -al /var/cache/nginx/
total 4
drwxr-xr-x 18 www-data root 360 Jun 20 21:21 .
drwxr-xr-x 19 root root 4096 Jul 5 20:26 ..
drwx------ 222 www-data www-data 4440 Jul 6 07:04 0
drwx------ 235 www-data www-data 4700 Jul 6 00:42 1
drwx------ 223 www-data www-data 4460 Jul 5 19:24 2
drwx------ 226 www-data www-data 4520 Jul 5 19:22 3
drwx------ 229 www-data www-data 4580 Jul 6 09:11 4
drwx------ 219 www-data www-data 4380 Jul 6 08:56 5
drwx------ 227 www-data www-data 4540 Jul 5 16:43 6
Your
/var/run
is not a symbolic link. You can add another tmpfs mount point.Any suggested size? I know it depends on the number of sites and the number of users, etc. so jsut a thumb-suck size would be fine.
It depends on RAM you have. You can set it to 50MB I guess. Session data is just textual data I guess!
This is one reason that I use a big common tmpfs dir and change application config.
@All
Please check “Edit cron on Debian/Ubuntu” section. Without it, you may run into errors/other issues.