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

Fixing session_start(): Permission Denied (13) — Verify PHP Configuration (php.ini)

3 min read
01.10.2025

What Does This Error Mean?

The error occurs when PHP cannot start a session because it cannot access the session storage directory (/var/lib/php/session). This is usually due to misconfiguration in php.ini, incorrect permissions, or ownership issues.

session_start php.ini Configuration
Verify session.save_path actually points where PHP can write.

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.

Locate and Edit php.ini

Find the Active php.ini File

Run:

php --ini | grep "Loaded Configuration File"

This will return something like:

Loaded Configuration File: /etc/php/8.0/apache2/php.ini

or

Loaded Configuration File: /etc/php/8.0/fpm/php.ini

If using Nginx, modify the php-fpm version (/etc/php/8.0/fpm/php.ini).

If using Apache, modify the apache2 version (/etc/php/8.0/apache2/php.ini).

Open php.ini

sudo nano /etc/php/8.0/apache2/php.ini

or for PHP-FPM:

sudo nano /etc/php/8.0/fpm/php.ini
Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

Verify and Update Session Settings

Find the following lines and ensure they are set correctly:

Ensure session.save_handler is set to files

session.save_handler = files

This tells PHP to use the default file-based session storage.

Set the Correct Session Directory

Find:

session.save_path = "/var/lib/php/session"

If it is missing or empty, add:

session.save_path = "/var/lib/php/session"

Increase session.gc_maxlifetime to Prevent Premature Session Expiry

session.gc_maxlifetime = 3600

This ensures that sessions do not expire too quickly.

Enable Strict Session Mode

session.use_strict_mode = 1

This prevents session hijacking by enforcing unique session IDs.

Ensure Cookie Settings Allow Sessions

Ensure:

session.cookie_secure = 0
session.cookie_httponly = 1

If session.cookie_secure = 1, PHP will not set cookies over HTTP.

Fix Permissions on /var/lib/php/session

If PHP cannot write session files, fix the directory permissions.

Set Correct Permissions

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

Set Correct Ownership

For Apache:

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

For Nginx:

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

Restart PHP and Web Server

For Apache:

sudo systemctl restart apache2

For Nginx & PHP-FPM:

sudo systemctl restart nginx php8.0-fpm

Try running the session script again.

Clear Old or Corrupt Session Files

If old or corrupt session files exist, PHP may fail to start new sessions.

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

Test if sessions work after clearing old data.

Debug with Logs

If sessions still do not work, check logs.

Check PHP Error Logs

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

or

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

Check System Logs

sudo journalctl -xe | grep php

Summary of Fixes

Issue Fix
Wrong session directory in php.ini Set session.save_path = "/var/lib/php/session"
Incorrect folder permissions chmod -R 770 /var/lib/php/session
Wrong ownership chown -R www-data:www-data /var/lib/php/session
Corrupt session files rm -rf /var/lib/php/session/*
Web server not restarted after changes Restart apache2 or php-fpm

By following these systematic fixes, you can resolve session_start() permission errors and restore PHP session functionality.

Frequently asked questions
`/tmp` typically — but PHP_FPM in some packagings defaults to `/var/lib/php/sessions/`. Verify with `php -i | grep session.save_path`. Empty value means "compile-time default" which differs by build. Always set an explicit path; defaults are unpredictable across distros.
`.user.ini` in document root: `session.save_path = "/home/user/sessions"`. PHP reads on each request (with 300s cache by default). Useful for shared hosting where each customer gets their own session dir, no cross-user reads possible. Verify the user PHP runs as can write to the specified path.
Sessions go to Redis instead of files; session.save_path becomes the Redis connection string (`tcp://127.0.0.1:6379`). Pros: faster, no file perms issues, multi-server safe. Cons: Redis dependency. For sites moving past file-based sessions, Redis is the standard upgrade — fixes this class of permission-denied errors entirely.
PHP-FPM didn't reload. After php.ini edits: `systemctl reload php-fpm` for FPM, `systemctl restart apache2` for mod_php. Verify with phpinfo() in browser shows the new value. If it doesn't, you edited the wrong php.ini (CLI version vs FPM version commonly confused).
Related articles
Fixing session_start(): No Such File or Directory Error in PHP
Fixing session_start(): Permission Denied (13) — Failed to Read Session Data in PHP
Fixing PHP session_start(): Permission Denied (13) Error