By umpire
After having issues doing anything on one of my Ubuntu 16.04 droplets due to disc usage errors, I found that I was running out of inodes and there are about 6.2m of them in /var/lib/php/sessions.
I recently updated from PHP 5 to PHP 7, I think this has caused the issue.
My questions are:
What’s the best way to clean sessions from this folder to free up inodes?
How can I prevent this from happening again?
I have this
09,39 * * * * root [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi
in etc/cron.d/php but it doesn’t appear to be working.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
I believe that this is a good approach.
What happens if you try to run the script manually:
/usr/lib/php/sessionclean
Do you get any errors?
Regards, Bobby
Heya,
If the problem persist and it’s not related only to the php session files, you can expand the search and check the disk space usage in other directories as well.
You can check which folders are using the most space on the Droplet by using the disk utilization command, du:
- du -h --max-depth=1 /
Check our tutorial on How to fix disk space issues here:
https://docs.digitalocean.com/support/how-do-i-fix-disk-space-issues-on-my-droplet/
There is also an ncurses interface for du, appropriately called ncdu, that you can install:
- sudo apt install ncdu
This will graphically represent your disk usage:
- ncdu
Output--- /root ----------------------------------------------------------------------
8.0KiB [##########] /.ssh
4.0KiB [##### ] /.cache
4.0KiB [##### ] .bashrc
4.0KiB [##### ] .profile
4.0KiB [##### ] .bash_history
You can step through the filesystem by using the up and down arrows and pressing Enter on any directory entry.
Hope that this helps!
/var/lib/php/sessions folder and prevent future inode exhaustion:You can safely remove stale session files to free up inodes. Here’s how:
find to delete session files older than a certain age, such as 24 hours:sudo find /var/lib/php/sessions -type f -mtime +1 -delete
This command deletes files modified more than 1 day ago. Adjust the +1 parameter based on your needs.
Clear All Session Files If you want to clear all files regardless of age, you can run:
sudo rm -rf /var/lib/php/sessions/*
sessionclean Script is WorkingYour cron job appears to call the sessionclean script. To troubleshoot why it isn’t working:
sessionclean Script Manually Run the script manually to ensure it works:sudo /usr/lib/php/sessionclean
If there are errors, investigate and resolve them.
Check session.gc_maxlifetime The sessionclean script relies on session.gc_maxlifetime to determine which files are considered stale. Ensure this value matches your intended cleanup policy:
sudo grep session.gc_maxlifetime /etc/php/7.*/cli/php.ini
Update it as needed (e.g., session.gc_maxlifetime = 1440 for 24 minutes) in both cli and fpm configurations:
sudo nano /etc/php/7.x/fpm/php.ini
sudo nano /etc/php/7.x/cli/php.ini
Debug the Cron Job
sudo systemctl status cron
- Check the cron logs for errors:
sudo grep CRON /var/log/syslog
- Verify the path to `sessionclean` is correct in the cron file.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.