The .cagefs/tmp directory stores temporary files for each user in CloudLinux CageFS. If it fills up, it can cause errors with PHP sessions, file uploads, and web applications.
/tmp directory located at /home/username/.cagefs/tmp.
Before deleting files, always check how much space is being used to identify problematic users or accounts.
du -sh /home/username/.cagefs/tmp
Replace username with the actual cPanel or system username.
# List all users' .cagefs/tmp sizes
for user in /home/*; do
user=$(basename $user);
if [ -d "/home/$user/.cagefs/tmp" ]; then
size=$(du -sh "/home/$user/.cagefs/tmp" 2>/dev/null | cut -f1);
echo "$user: $size";
fi;
done | sort -k2 -hr
If any directory shows excessive usage (hundreds of MB or GB), it likely needs cleaning.
.cagefs/tmp. Only delete temporary files, not the directory itself. Avoid deleting files that are actively being used by running processes.
# Delete all files inside the directory but keep the directory
rm -rf /home/username/.cagefs/tmp/*
# Alternative: Delete only old files (older than 7 days)
find /home/username/.cagefs/tmp -type f -mtime +7 -delete
find /home/*/.cagefs/tmp -type f -delete
# Delete files older than 3 days
find /home/*/.cagefs/tmp -type f -mtime +3 -delete
The -mtime +N option deletes files older than N days, which is safer as it preserves recent temporary files that might still be in use.
After deleting files, it's important to restore correct permissions so PHP and other services can continue to use the temporary directory.
# Set correct ownership
chown -R username:username /home/username/.cagefs/tmp
# Set secure permissions (sticky bit allows only file owners to delete their files)
chmod -R 1777 /home/username/.cagefs/tmp
1777 means: read/write/execute for everyone (777) with the sticky bit (1). The sticky bit ensures users can only delete their own files in the directory, not other users' files.
After cleaning and fixing permissions, restart web services to ensure PHP sessions work correctly:
# Restart Apache (or httpd on CentOS)
sudo systemctl restart apache2
# Restart PHP-FPM (adjust version as needed)
sudo systemctl restart php7.4-fpm
sudo systemctl restart php8.0-fpm
# For systems with both, restart all relevant services
sudo systemctl restart lvectl
To prevent .cagefs/tmp from filling up in the future, set up an automated cleanup schedule.
Edit the system crontab (as root):
sudo crontab -e
# Delete files older than 7 days in all users' .cagefs/tmp
0 3 * * * find /home/*/.cagefs/tmp -type f -mtime +7 -delete
# Delete files older than 24 hours, runs every 6 hours
0 */6 * * * find /home/*/.cagefs/tmp -type f -mtime +1 -delete
# Weekly cleanup with logging
0 2 * * 0 find /home/*/.cagefs/tmp -type f -mtime +7 -delete >> /var/log/cagefs_cleanup.log 2>&1
After adding your preferred schedule, save the crontab file (Ctrl+O, Enter, Ctrl+X in nano).
/var/log/cagefs_cleanup.log periodically to ensure the cleanup is working and to monitor disk space trends.
| Issue | Fix |
|---|---|
| .cagefs/tmp using too much space | rm -rf /home/username/.cagefs/tmp/* (single user)find /home/*/.cagefs/tmp -type f -delete (all users) |
| Web applications failing due to full /tmp | Clean .cagefs/tmp and optionally set upload_tmp_dir in php.ini |
| Wrong permissions after deletion | chmod -R 1777 /home/username/.cagefs/tmp |
| Need to prevent future disk fills | Add cron job: 0 3 * * * find /home/*/.cagefs/tmp -type f -mtime +7 -delete |
| PHP session errors after cleanup | Restart Apache and PHP-FPM services |
Following these steps will keep your CloudLinux CageFS temporary directories clean, secure, and optimized for performance!