Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP reports 'write failed: No space left on device'

Errorwrite failed: No space left on device

Short 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.

  • Applies to PHP 8.3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 /tmp
  2. 2Match what you see, then jump to its fix

    1. 1df -h shows Use% 100% for the file systemThe disk is out of blocksFix
    2. 2df -h shows space left but df -i shows IUse% 100%The disk has free blocks but no free inodesFix
    3. 3session_start() fails while other writes on the server workThe session save path sits on a small or shared file systemFix

What does the error look like?

  • write failed: No space left on device
  • session_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 -h

2Fix

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.log

3Verify

df -h shows free space for that file system, and the PHP write works.

df -h

Confirmed by gnu.org

Did this fix it?

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 -i

2Fix

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 -l

3Verify

df -i shows free inodes again.

df -i /var/lib/php/sessions

Confirmed by gnu.org

Did this fix it?

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 = 1440

3Verify

Restart PHP-FPM or Apache, then load a page that starts a session.

sudo systemctl restart php8.3-fpm

Confirmed by php.net

Did this fix it?

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

Back 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 fix

Back 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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.