Plesk PHP Session Cleanup unable to delete files from /var/lib/php/session

I'm using 11.0.9 CentOS 6 110120608.16

All session files on my server are stored in the folder /var/lib/php/session

The folder has the following permissions set:

drwx-wx-wt 2 root root 548864 Apr 10 20:09 session

But all session files inside that folder only have rw permissions for there apache user exclusively

So I think the cron configured in /etc/cron.hourly/plesk-php-cleanuper is unable to actually perform the session cleanup, hence the size of the folder continues to grow and at this point every time the job runs and combs through all files the I/O weight goes to 100% and slows my entire server down to the point where the applications hosted on it are completely unaccessible.

How can I resolve this matter?
Who is Participating?
SWB-ConsultingConnect With a Mentor Author Commented:
Actually I figured it out: I changed the permissions from the officially prescribed Plesk ones (1733) to 733. Now the root user can delete files in that folder.
Zephyr ICTCloud ArchitectCommented:
I think you can set the rights on this folder as follows:

chmod 1777 /var/lib/php/session

Using sticky bit nobody can change the rights on this folder but the root user.
SWB-ConsultingAuthor Commented:
OK, but how do I get the actual session files to be generated so they're accessible to the root user? Right now they are only generated with rw permissions to the apache user.
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

Zephyr ICTCloud ArchitectCommented:
So the files get created with user apache:apache in rw? Is that the issue? I'm sorry, might have misunderstood ...

I'm assuming you already did the upgrade: ??
SWB-ConsultingAuthor Commented:
No worries, yes I did that workaround on there. But I'm actually running PHP as module so not sure if that applies.

Yes, the problem seems to be that all session files are created with rw permission for ONLY the apache user. But the cleanup job is run under root.

Even when I try to remove a single file in that folder as root user it won't do it, it just finishes the delete command without any response and nothing has changed.
Zephyr ICTCloud ArchitectCommented:
You can change the permissions on those file though, no?

chmod 777 /var/lib/php/session/*

or change the owner for all files in that directory first then run the script again for cleanup?

chown root:root /var/lib/php/session/*
SWB-ConsultingAuthor Commented:
True, if I do it manually one time I could do that. But on an ongoing basis I have an automated job running that always tries to remove those files.

Or I could maybe just run the job as a crontab under the apache user.

I understand and appreciate your idea, but it strikes me as a bit of a patch/workaround. Everything that is in place right now is the way plesk seems to have it set by default, so I'm wondering if there isn't some way to get the session files saved with less restrictive permissions?

I can't be the only one on plesk with this issue (although I haven't found anyone with exactly this issue)
SWB-ConsultingAuthor Commented:
This is the cronjob that plesk has created to cleanup sessions:

[ -x /usr/lib64/plesk-9.0/maxlifetime ] && [ -d /var/lib/php/session ] && find /var/lib/php/session -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib64/plesk-9.0/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete

Open in new window

SWB-ConsultingAuthor Commented:
I found the problem.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.