Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

Fixing session_start(): Permission Denied (13) — Failed to Read Session Data in PHP

4 min read
09.06.2025

What Does This Error Mean?

The error occurs when PHP cannot access the session storage directory due to permission issues, incorrect configuration, or missing session files.

session_start Read Permission Denied
Failed to read session — owner/mode mismatch, or SELinux relabel needed.

For closely related session_start / permission errors, see Fixing session_start() failed: Permission denied (13) — sysadmin guide, "No Space Left on Device (28)" & Session Write Errors, and Debugging session_start() Errors Using Logs.

Common Causes:

  1. Incorrect PHP session directory permissions (Apache/Nginx cannot write session files).
  2. Wrong ownership of session files (files owned by root instead of www-data or nginx).
  3. PHP misconfiguration (wrong session.save_path in php.ini).
  4. SELinux or AppArmor restrictions preventing access.
  5. Full disk space or missing session folder.
  6. Corrupt session files preventing new sessions from being created.

Find the PHP Session Save Path

First, determine where PHP is storing session files.

Check PHP Session Path Using Command Line

Run:

php -i | grep "session.save_path"

or

php -r 'echo session_save_path();'

Expected output:

session.save_path => /var/lib/php/sessions

If the session path is empty (session.save_path =>), it means PHP is using the system's default temporary folder (/tmp).

Ensure the Session Directory Exists

If the session directory does not exist, create it.

If session.save_path is /var/lib/php/sessions

sudo mkdir -p /var/lib/php/sessions

If session.save_path is /tmp

sudo mkdir -p /tmp/php_sessions

Then update php.ini to use this path (see Step 5).

Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

Fix Permissions on Session Directory

PHP needs read and write access to the session directory.

Set Correct Permissions

sudo chmod -R 770 /var/lib/php/sessions

or if using /tmp:

sudo chmod -R 770 /tmp/php_sessions

Set Correct Ownership

For Apache:

sudo chown -R www-data:www-data /var/lib/php/sessions

For Nginx:

sudo chown -R nginx:nginx /var/lib/php/sessions

Restart Apache/Nginx and test again:

sudo systemctl restart apache2

or

sudo systemctl restart nginx php8.0-fpm

Check for SELinux or AppArmor Restrictions

If SELinux or AppArmor is blocking PHP from writing session files, allow access.

Check SELinux Status

sestatus

If SELinux is enabled, grant access:

sudo chcon -R -t httpd_sys_rw_content_t /var/lib/php/sessions

To disable SELinux temporarily:

sudo setenforce 0

Check AppArmor (Debian/Ubuntu)

If AppArmor blocks PHP session writes, allow PHP-FPM:

sudo aa-complain /usr/sbin/php-fpm

Restart services and check again.

Verify php.ini Configuration

If PHP is using the wrong session path, update php.ini.

Locate php.ini

Run:

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

Update Session Settings

Find and modify:

session.save_handler = files
session.save_path = "/var/lib/php/sessions"
session.gc_maxlifetime = 3600
session.use_strict_mode = 1
session.cookie_secure = 0

If /var/lib/php/sessions is restricted, use /tmp/php_sessions instead.

Restart PHP & Web Server

sudo systemctl restart php8.0-fpm
sudo systemctl restart apache2

Clear Old or Corrupt Session Files

Corrupt session files can prevent new ones from being created.

Clear Old Sessions

sudo rm -rf /var/lib/php/sessions/*

or

sudo rm -rf /tmp/php_sessions/*

Run the session test script again.

Check for Full Disk Space or Inodes

If the server has no free space, PHP cannot create session files.

Check Disk Space

df -h

If /var or /tmp is 100% full, delete unnecessary files:

sudo rm -rf /var/lib/php/sessions/*

Check Inodes

df -i

If inodes are full, clear temp files:

sudo rm -rf /tmp/*

Restart services and try again.

Debug with Error Logs

If the issue persists, check logs.

Check Apache Logs

sudo tail -f /var/log/apache2/error.log

Check Nginx Logs

sudo tail -f /var/log/nginx/error.log

Check PHP Logs

sudo tail -f /var/log/php8.0-fpm.log

By following these steps, your PHP sessions should start working properly.

Summary of Fixes

Issue Fix
Session directory missing mkdir -p /var/lib/php/sessions
Incorrect folder permissions chmod -R 770 /var/lib/php/sessions
Wrong ownership chown -R www-data:www-data /var/lib/php/sessions
SELinux/AppArmor blocking access chcon -R -t httpd_sys_rw_content_t /var/lib/php/sessions
Full disk space or inodes df -h, df -i, then clear space
Misconfigured php.ini Update session.save_path
Corrupt session files rm -rf /var/lib/php/sessions/*

By following this step-by-step troubleshooting guide, you can fix PHP session permission errors, ensure session files are properly written, and restore session functionality.

Frequently asked questions
Directory mode and individual file mode are independent. Mode 770 on dir lets owner+group write new files; mode 600 on individual session files lets only the writing user read. Another user (e.g., different PHP-FPM pool) writes, then can't read its own file because owner switched. Set process to consistent user, or relax file mode to 660.
Each pool runs as a different user. If session.save_path is shared, pool1 writes sessions owned by user1; pool2 can't read them. Either: per-pool session.save_path (each gets its own dir), or shared save_path with chmod 770 + group ownership so all PHP users in that group can read each others' sessions (security trade-off).
After moving session.save_path to a custom location (not /var/lib/php/sessions). SELinux remembers the *original* context of the dir; PHP can't write to a dir labeled `home_root_t`. `chcon -R -t httpd_sys_rw_content_t ` relabels. Verify with `ls -Z`. For permanent labels, use `semanage fcontext -a` to make the change survive `restorecon`.
PHP's session.gc_probability/divisor (e.g., 1/100) runs cleanup on a fraction of requests. Low-traffic sites accumulate stale files. Force cleanup via cron: `0 4 * * * find /var/lib/php/sessions/ -name 'sess_*' -mmin +1440 -delete`. Or raise gc_probability to 5 (5% chance per request). Or migrate to Redis-based sessions to eliminate file accumulation.
Related articles
Fixing PHP session_start(): Permission Denied (13) Error
Fixing session_start(): No Such File or Directory Error in PHP
Fixing session_start() failed: Permission denied (13) — A System Administrator's Guide