PHP reports 'write failed: No space left on device'
write failed: No space left on deviceShort answer
The file system holding the target path has no free blocks or no free inodes, so the write failed. Run df -h and df -i on the path PHP writes to. A full block count and an exhausted inode count need different cleanups. Often the path is the session or upload directory.
Fix it fast
1Find out which cause you have
Check both block and inode usage on the file system PHP writes to. One of them will show 100%.
df -h /var/lib/php /tmp df -i /var/lib/php /tmp2Match what you see, then jump to its fix
What does the error look like?
write failed: No space left on devicesession_start(): Failed to write session data
Cause 1 of 3
The disk is out of blocks
1Check
df -h prints sizes in readable units; find which file system the failing path is on.
df -h2Fix
Free space on that file system by removing files you have identified as unneeded, such as old logs and temporary uploads, or grow the volume.
# remove files you have identified as safe to delete, for example:
sudo rm /var/log/myapp/old-export.log3Verify
df -h shows free space for that file system, and the PHP write works.
df -hConfirmed by gnu.org
Cause 2 of 3
The disk has free blocks but no free inodes
1Check
df -i lists inode usage instead of block usage. Millions of tiny files, such as old session files, use up inodes first.
df -i2Fix
Find the folder holding very many small files and remove the stale ones. For session files, keep only those still within your session lifetime, and make sure PHP's garbage collection can run (see the next cause).
# look at what fills the folder first
ls /var/lib/php/sessions | wc -l3Verify
df -i shows free inodes again.
df -i /var/lib/php/sessionsConfirmed by gnu.org
Cause 3 of 3
The session save path sits on a small or shared file system
1Check
session.save_path decides where the files handler writes. The manual warns against a world-readable directory such as /tmp, and that garbage collection stops if the N levels argument is used.
php -r 'echo ini_get("session.save_path"), PHP_EOL, ini_get("session.gc_maxlifetime"), PHP_EOL;'2Fix
Point session.save_path at a dedicated directory on a file system with room, and keep gc_maxlifetime at the value you really need so old files are collected.
; php.ini
session.save_path = "/var/lib/php/sessions"
session.gc_maxlifetime = 14403Verify
Restart PHP-FPM or Apache, then load a page that starts a session.
sudo systemctl restart php8.3-fpmConfirmed by php.net
How do I stop it coming back?
- Alert when any file system passes 80% in blocks or inodes.
- Rotate and cap logs.
- Keep sessions and uploads on a volume you monitor.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Databases
MySQL fails with Error writing file ... (errno 28)
Error writing file '%s' (errno: %d - %s)
Errno 28 is the operating system saying there is no space left on the device.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack end
CodeIgniter 4 cannot write its cache files
CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/
CodeIgniter 4's file cache needs a cache directory that the web server can really write to.
2 causes, each with a fixBack end
CodeIgniter 3 loads the model but the property is undefined
The model name you are loading is the name of a resource that is already being used: user
CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.
2 causes, each with a fix