How We Fixed a 503 Service Unavailable Error on CyberPanel: PHP Session Files Exhausted All Server Inodes
Introduction
A website returning 503 Service Unavailable can be frustrating, especially when multiple websites hosted on the same VPS suddenly become inaccessible.
Recently, we encountered this issue on a VPS running Ubuntu 22.04, CyberPanel, OpenLiteSpeed, and PHP 8.3. Initially, the problem appeared to be related to the web server. However, after investigating the filesystem, we discovered a less obvious cause: the server had exhausted all available inodes because millions of PHP session files had accumulated.
In this article, we explain what happened, how we identified the root cause, how we restored the websites, and what we implemented to prevent the problem from happening again.
1. The Problem: All Websites Returned 503
The incident started when hosted websites began displaying:
503 Service Unavailable
During the initial investigation, we checked the OpenLiteSpeed service:
sudo systemctl status lsws
The service was failing to start correctly. Its logs included an error similar to:
[ERROR] Failed to write to pid file:
/tmp/lshttpd/lshttpd.pid
MariaDB and CyberPanel were running, but OpenLiteSpeed could not operate normally.
We also checked the available disk space. Surprisingly, the server still had plenty of free storage.
This led us to investigate another important filesystem resource: inodes.
2. The Real Cause: 100% Inode Usage
An inode is a filesystem data structure that stores information about a file or directory. Every file requires an inode.
A filesystem can have free disk space but still fail to create new files when all its inodes are consumed.
We checked inode usage using:
df -i /
The result showed:
| Metric | Value |
|---|---|
| Total inodes | 12,902,400 |
| Used inodes | 12,902,400 |
| Free inodes | 0 |
| Usage | 100% |
The root filesystem had completely run out of available inodes.
Next, we investigated which directory was consuming them:
sudo du --inodes -x -d 1 /
The investigation identified /var as the major contributor.
Further investigation revealed that the PHP session directory was responsible for almost all the inode consumption:
/var/lib/lsphp/session/lsphp83
It contained approximately 11.86 million PHP session files.
3. Why Were Millions of PHP Session Files Accumulating?
PHP uses session files to store information about user sessions, such as login state and other session data.
In this server, PHP 8.3 was configured to store session files in:
/var/lib/lsphp/session/lsphp83
We inspected the PHP session configuration:
/usr/local/lsws/lsphp83/bin/php -i | grep -E 'session.save_path|session.gc_maxlifetime|session.gc_probability|session.gc_divisor'
The important settings were:
session.gc_maxlifetime = 14400
session.gc_probability = 0
session.gc_divisor = 1000
The critical setting was:
session.gc_probability = 0
This disabled PHP's probabilistic session garbage collection.
As a result, expired session files were not being removed through PHP's normal garbage-collection mechanism. Over time, millions of old files accumulated.
The result was inode exhaustion, which prevented the server from creating files required for normal operation.
4. Immediate Fix: Remove Expired PHP Session Files
Once we identified the problem, we performed a targeted cleanup.
First, we stopped OpenLiteSpeed:
sudo systemctl stop lsws
Then we removed PHP 8.3 session files older than four hours:
sudo find /var/lib/lsphp/session/lsphp83 \
-maxdepth 1 -type f -name 'sess_*' -mmin +240 -delete
This command targeted only regular PHP session files older than 240 minutes in the identified directory.
After cleanup, inode usage dropped dramatically:
| Metric | Before cleanup | After cleanup |
|---|---|---|
| Used inodes | 12,902,400 | 1,038,620 |
| Free inodes | 0 | 11,863,780 |
| Inode usage | 100% | 9% |
Approximately 11.86 million inodes were recovered.
Next, we reset the failed service state and started OpenLiteSpeed again:
sudo systemctl reset-failed lsws
sudo systemctl start lsws
We verified the service:
sudo systemctl status lsws --no-pager
OpenLiteSpeed successfully returned to:
Active: active (running)
5. Permanent Fix: Enable PHP Session Garbage Collection
Removing old session files restored the server, but we also needed to prevent the same issue from happening again.
We backed up the PHP configuration file:
sudo cp \
/usr/local/lsws/lsphp83/etc/php/8.3/litespeed/php.ini \
/usr/local/lsws/lsphp83/etc/php/8.3/litespeed/php.ini.backup
We then updated the garbage-collection settings:
session.gc_maxlifetime = 14400
session.gc_probability = 1
session.gc_divisor = 100
These settings mean:
-
session.gc_maxlifetime = 14400: Session data older than four hours is eligible for garbage collection. -
session.gc_probability = 1: Sets the probability numerator. -
session.gc_divisor = 100: Gives a 1-in-100 probability when PHP triggers the garbage-collection check.
The updated configuration was verified using:
/usr/local/lsws/lsphp83/bin/php -i | grep -E 'session.gc_maxlifetime|session.gc_probability|session.gc_divisor'
6. Automatic Daily Cleanup Using Cron
PHP's probabilistic garbage collection alone does not guarantee that expired files will be removed on a fixed schedule.
For additional protection, we created a dedicated cleanup script.
File location:
/usr/local/bin/lsphp83-session-cleanup.sh
Script contents:
#!/bin/bash
find /var/lib/lsphp/session/lsphp83 \
-type f -name 'sess_*' -mmin +240 -delete
We secured the script:
sudo chmod 700 /usr/local/bin/lsphp83-session-cleanup.sh
Next, we created a cron job:
sudo nano /etc/cron.d/lsphp83-session-cleanup
Added:
30 3 * * * root /usr/local/bin/lsphp83-session-cleanup.sh
This schedules the cleanup every day at 03:30 server time.
We verified that the cron service was running:
sudo systemctl status cron --no-pager
The cron daemon was active.
Important: The cleanup policy removes session files older than four hours, so users whose sessions have expired may need to log in again. The policy should be reviewed if applications require longer sessions.
7. Final Verification: Websites and CyberPanel Restored
After restarting OpenLiteSpeed, we checked the website and CyberPanel endpoints.
Website:
curl -I https://rmservices.in
Result:
HTTP/2 200
CyberPanel:
curl -I https://secure1000.rmservices.in:8090
Result:
HTTP/1.1 200 OK
We also checked inode usage again:
df -i /
The filesystem showed approximately 9% inode usage.
The two tested endpoints were responding successfully, and OpenLiteSpeed was running normally.
8. Useful Commands for Future Monitoring
Server administrators can use these commands to monitor filesystem health.
Check disk space:
df -h
Check inode usage:
df -i
Find directories consuming the most inodes:
sudo du --inodes -x -d 1 /var
Check PHP session directory inode usage:
sudo du --inodes -d 1 /var/lib/lsphp/session
Check OpenLiteSpeed status:
sudo systemctl status lsws --no-pager
Check cron status:
sudo systemctl status cron --no-pager
Conclusion
This incident demonstrated why monitoring disk space alone is not enough for Linux server administration.
Even with sufficient free storage, a server can become unavailable when its filesystem runs out of inodes.
In our case, millions of old PHP session files consumed almost all available inodes. By identifying the PHP session directory, removing expired session files, correcting PHP garbage-collection settings, and implementing scheduled cleanup, we restored the affected services and added preventive maintenance.
The key lesson: Always monitor both disk space and inode usage on production servers.
Technical environment
-
Operating System: Ubuntu 22.04 LTS
-
Control Panel: CyberPanel 2.5.1
-
Web Server: OpenLiteSpeed
-
PHP: 8.3
-
Database: MariaDB 10.11
-
Session Storage: Filesystem
-
Cleanup Scheduler: Linux Cron
This article documents a real troubleshooting and recovery process. Commands and configuration paths should be checked against your own server environment before use.