The error message:
session_write_close(): write failed: no space left on device (28)
session_write_close(): failed to write session data (files).
please verify that the current setting of session.save_path is correct (/var/lib/php/sessions)
indicates that PHP cannot save session data because the server has run out of disk space or inodes.
Run the following command:
df -h
If /var or /tmp is 100% full, free up space by deleting unnecessary files:
sudo rm -rf /var/log/*.gz
sudo rm -rf /var/tmp/*
sudo rm -rf /tmp/*
After freeing space, restart Apache or Nginx:
sudo systemctl restart apache2
or
sudo systemctl restart nginx
Even if disk space is not full, inodes might be exhausted.
Check inode usage:
df -i
If inodes are full (e.g., 100% usage), clear unused session files:
sudo rm -rf /var/lib/php/sessions/*
sudo systemctl restart php8.0-fpm
sudo systemctl restart apache2
If the error persists, check the session storage path.
Find your active PHP configuration:
php --ini | grep "Loaded Configuration File"
Edit the file:
sudo nano /etc/php/8.0/apache2/php.ini
or for PHP-FPM:
sudo nano /etc/php/8.0/fpm/php.ini
Find:
session.save_path = "/var/lib/php/sessions"
If /var/lib/php/sessions is full or restricted, use /tmp/php_sessions instead:
session.save_path = "/tmp/php_sessions"
sudo systemctl restart php8.0-fpm
sudo systemctl restart apache2
Ensure PHP can write to the session folder:
sudo chmod -R 770 /var/lib/php/sessions
sudo chown -R www-data:www-data /var/lib/php/sessions # For Apache
sudo chown -R nginx:nginx /var/lib/php/sessions # For Nginx
| Issue | Fix |
|---|---|
| Disk space full | Run df -h and delete unnecessary files |
| Inodes full | Run df -i and delete session files |
| Wrong session.save_path | Change it to /tmp/php_sessions in php.ini |
| Permissions issue | Set chmod -R 770 /var/lib/php/sessions |
Now PHP sessions should work properly!