Applicable to:
- Plesk for Linux
Symptoms
PHP session files in folder /var/lib/php/session/
are not removed automatically.
Cause
Session file folder was changed from default /var/lib/php/session/
:
# grep -ir session.save_path /opt/plesk/php/*/etc/php.ini | grep -v ";"
/opt/plesk/php/7.4/etc/php.ini:session.save_path = "/var/lib/php74/session"
Resolution
Apply one of the following solutions:
-
Open Tools & Settings > PHP Settings and select the PHP handler with changed session.save_path value
-
Click on php.ini tab
-
Find
session.save_path
parameter and set it to/var/lib/php/session
-
Access the server via SSH
-
Copy original task:
# cp /etc/cron.hourly/plesk-php-cleanuper /etc/cron.hourly/php74-cleaner
-
Edit the file php74-cleaner and change the last line to the following:
[ -x /usr/lib64/plesk-9.0/maxlifetime ] && [ -d /var/lib/php/session ] && /usr/lib64/plesk-9.0/php_session_cleaner /var/lib/php74/session $(/usr/lib64/plesk-9.0/maxlifetime)
Comments
10 comments
How is the script called in Plesk 17? there is no such file in the cron.hourly!
Hello @Robert Kühn,
The file mentioned in the article belongs to root's crontab.
Please make sure that you are logged in as root or accessing the /etc/cron.hourly with sudo. Otherwise, you will see the crontab of the user you are logged in with.
Thank you @Nick Plekhov,
I just used the root user per ssh-console and even with sudo I can see only a ".placeholder" file inside. I just checked also the crontab with sudo and found only something like: /opt/psa/admin/bin/php -dauto_prepend_file=sdk.php '/opt/psa/admin/plib/modules/xovi/scripts/clear-cache.php' ..
Hello @Robert Kühn
In this case, I suggest you create the file manually.
The content should be as follows:
pgrep -f ".*$0$" | grep -qv $$ && exit 0
renice 19 -p $$ >/dev/null 2>&1
[ -x /usr/lib64/plesk-9.0/maxlifetime ] && [ -d /var/lib/php/session ] && /usr/lib64/plesk-9.0/php_session_cleaner /var/lib/php/session $(/usr/lib64/plesk-9.0/maxlifetime)
After the file is created change the permissions as follows:
chmod 755 /etc/cron.hourly/plesk-php-cleanuper
Hello @Robert Kühn,
the cleanup script /usr/lib/php/sessionclean is called via /etc/cron.d/php in Plesk 17.
Same for /usr/lib/php5/sessionclean and /etc/cron.d/php5, but that one is broken in 17.8.
Hello,
I would like to ensure you, that /etc/cron.hourly/plesk-php-cleanuper is the cron script for PHP session path clean up in all Plesk Onyx versions.
ls: cannot access /etc/cron.hourly/plesk-php-cleanuper: No such file or directory
/usr/lib64/plesk-9.0 doesn't exist.
However this does: /usr/lib/plesk-9.0/php_session_cleaner
But there is no maxlifetime in /usr/lib/plesk-9.0/.
Product version: Plesk Onyx 17.8.11 Update #73
Anyway, I rewrote /usr/lib/php/sessionclean a bit so it cleans up plesk's default session dirs too, so that works for us.
Is it
/var/lib/phpXX/session or /var/lib/phpXX/sessions
does it matter?
Hello @highr0ll34,
Yes it's metter.
Using below command you should find what exactly custom path for "session.save_path" is set.
grep -ir session.save_path /opt/plesk/php/*/etc/php.ini | grep -v ";"
Found path must exist on the server.
This path must be used in point 4 of Resolution
For some reason, I started seeing the sess_ files in my /tmp folder too on my Obsidian server.
Despite all php.ini files showing /var/lib/php/session as the session.save_path..
I had to edit /etc/cron.hourly/plesk-php-cleanuper to add cleanup of the /tmp folder.
Please sign in to leave a comment.