session save path 🐘 PHP

Warning: session_start(): open(/var/lib/php/sessions/sess_x, O_RDWR) failed: Permission denied

PHP can’t write session files to the configured session.save_path.

Seen on: PHP

Meaning

The session directory must be writable by the PHP process user. After changing the PHP-FPM user, restoring from backup or using a custom save path, permissions often don’t match.

Common causes

  • save_path owned by another user
  • Directory doesn’t exist
  • Disk full
  • SELinux context blocking writes

⚡ Quick fix

  1. Check session.save_path in phpinfo()
  2. Make the directory writable by the PHP user
  3. Use a path inside your app (e.g. storage/sessions) or a Redis session handler

Detailed fix by platform

Linux

  1. sudo chown -R www-data:www-data /var/lib/php/sessions && sudo chmod 1733 /var/lib/php/sessions

How to diagnose

  1. Path — Which save path?
  2. Owner — Who owns it vs which user runs PHP?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.