The .cagefs/tmp directory is part of the CloudLinux CageFS system, which isolates users in a secure environment. This directory is used for temporary files created by web applications running under CageFS.
The .cagefs/tmp directory serves several critical functions in the CloudLinux security architecture:
/tmp directory inside .cagefs, preventing access to other users' temporary files./tmp directory or other users' files..cagefs/tmp instead of the global /tmp./home/exampleuser/.cagefs/tmp. Inside their virtual environment, this appears as /tmp.
If a web application cannot write to .cagefs/tmp, you'll see permission errors in logs. This typically happens after incorrect manual file operations or service changes.
# Set correct ownership (replace 'username' with actual username)
sudo chown -R username:username /home/username/.cagefs/tmp
# Set secure permissions with sticky bit
sudo chmod -R 1777 /home/username/.cagefs/tmp
1777 includes the sticky bit (1) which ensures users can only delete their own files, plus read/write/execute for all (777). This is standard for /tmp directories.
sudo systemctl restart cagefs
sudo systemctl restart apache2 # or httpd on CentOS
sudo systemctl restart php7.4-fpm # adjust PHP version as needed
When .cagefs/tmp fills up, PHP sessions, file uploads, and other temporary operations will fail with disk space errors.
# Check specific user's tmp usage
du -sh /home/username/.cagefs/tmp
# Check inode usage (sometimes files are small but numerous)
find /home/username/.cagefs/tmp -type f | wc -l
# Remove all files (preserves directory structure)
sudo rm -rf /home/username/.cagefs/tmp/*
# Or remove only old files (safer, preserves recent files)
sudo find /home/username/.cagefs/tmp -type f -mtime +3 -delete
rm -rf command is powerful. Double-check the path before executing. Using -mtime +N to delete only old files is safer for production systems.
# Set up monitoring
df -h /home/username/.cagefs/tmp
# Consider automated cleanup via cron
# Add to crontab: 0 3 * * * find /home/username/.cagefs/tmp -type f -mtime +7 -delete
If PHP cannot store session files, session_start() will fail, breaking user logins and sessions in web applications.
# Check current PHP session configuration
php -i | grep session.save_path
# For web server PHP, create a test file:
echo "<?php phpinfo(); ?>" > /home/username/public_html/session_test.php
# Then visit http://domain.com/session_test.php and search for session.save_path
# REMOVE this file after testing!
# Edit php.ini (adjust path for your system)
# For CentOS/RHEL:
sudo nano /etc/php.ini
# For Ubuntu/Debian Apache:
sudo nano /etc/php/7.4/apache2/php.ini
# For Ubuntu/Debian PHP-FPM:
sudo nano /etc/php/7.4/fpm/php.ini
Find the session.save_path line and update it to point to the user's CageFS temp directory:
session.save_path = "/home/username/.cagefs/tmp"
Save the file (Ctrl+O, Enter, Ctrl+X).
sudo systemctl restart apache2 # or httpd
sudo systemctl restart php7.4-fpm # adjust version
File uploads in PHP applications fail when the temporary upload directory is not writable or incorrectly configured.
php -i | grep upload_tmp_dir
# Edit php.ini (adjust path for your system)
sudo nano /etc/php.ini # or appropriate php.ini
# Find and update upload_tmp_dir:
upload_tmp_dir = "/home/username/.cagefs/tmp"
# Also ensure these related settings are appropriate:
upload_max_filesize = 64M
post_max_size = 64M
max_file_uploads = 20
upload_tmp_dir, also verify that upload_max_filesize and post_max_size are set appropriately for your application's needs.
# Test if PHP can write to the directory
sudo -u username php -r "echo is_writable('/home/username/.cagefs/tmp') ? 'Writable' : 'NOT Writable';"
# If not writable, ensure permissions are correct (as in Section 2)
sudo systemctl restart apache2
sudo systemctl restart php7.4-fpm
sudo systemctl restart cagefs
| Issue | Fix |
|---|---|
| "Permission Denied" in .cagefs/tmp | chmod -R 1777 /home/username/.cagefs/tmp |
| "No Space Left on Device" error | rm -rf /home/username/.cagefs/tmp/* or use find ... -mtime +N -delete |
| PHP Sessions Not Working (session_start() fails) | Set session.save_path = "/home/username/.cagefs/tmp" in php.ini |
| File Uploads Failing | Set upload_tmp_dir = "/home/username/.cagefs/tmp" in php.ini |
| Services not recognizing changes | Restart Apache/PHP-FPM: systemctl restart apache2 php7.4-fpm cagefs |
Understanding and properly configuring the .cagefs/tmp directory is essential for maintaining secure, functional web applications in CloudLinux CageFS environments!