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

Debugging session_start() Errors in PHP Using Error Logs

3 min read
29.12.2025

Enable Error Logging in PHP

To get detailed error messages, enable error reporting in php.ini.

Debugging session_start Errors PHP
session_start fails — error log first; the message names the cause.

For related session and PHP-debug topics, see Fixing session_start() failed: Permission denied (13), Fixing "No Space Left on Device (28)" & Session Write Errors, and Enable PHP Error Reporting for mysql.php Troubleshooting.

Locate php.ini

Find the active PHP configuration:

php --ini | grep "Loaded Configuration File"

Edit php.ini:

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

or (for PHP-FPM)

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

Enable Error Display and Logging

Find and modify:

log_errors = On
error_log = /var/log/php_errors.log
display_errors = On
display_startup_errors = On

Restart PHP & Web Server

sudo systemctl restart apache2

or

sudo systemctl restart nginx php8.0-fpm

Now, PHP will log all errors to /var/log/php_errors.log.

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

Check Web Server Logs

Check Apache Logs

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

or (for CentOS/RHEL):

sudo tail -f /var/log/httpd/error_log

Check Nginx Logs

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

Check PHP Logs

If PHP is running as FPM (FastCGI Process Manager):

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

Check System Logs for Security Restrictions

If the logs show "Permission denied (13)", SELinux or AppArmor may be blocking PHP.

Check SELinux Logs

sudo journalctl -xe | grep AVC

or

sudo grep "denied" /var/log/audit/audit.log

If SELinux is blocking PHP sessions:

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

Check AppArmor Logs (Ubuntu/Debian)

sudo aa-status
sudo dmesg | grep php

If AppArmor is blocking PHP sessions:

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

Debug with a Test Script

If no useful logs appear, create a PHP debug script.

Create a File (debug.php)

sudo nano /var/www/html/debug.php

Paste this:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

session_start();

if (!session_id()) {
    echo "Session failed to start! Check logs.";
} else {
    echo "Session started successfully!";
}
?>

Run the Script in Browser

Go to:

http://yourserver.com/debug.php

or run from CLI:

php /var/www/html/debug.php

If an error appears, check logs and apply fixes accordingly.

Summary of Debugging Steps

Step Command / Action
Enable PHP error logging Edit php.ini, set log_errors = On, display_errors = On
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/php_errors.log
Check SELinux restrictions sudo journalctl -xe | grep AVC
Check AppArmor restrictions sudo aa-status
Test with debug script Create debug.php and check output

By following these debugging steps, you can identify and fix session errors in PHP quickly.

Frequently asked questions
Depends on SAPI. Apache mod_php: usually `/var/log/apache2/error.log` or set by `error_log` in php.ini. PHP-FPM: configured in pool's `php_admin_value[error_log]` or php.ini, often `/var/log/php-fpm/error.log`. CLI: stderr by default. Find with `php -i | grep error_log` for the active SAPI. If `error_log` is empty in phpinfo, logs go to the web server log.
No. `display_errors = Off`, `log_errors = On`, `error_log = /path/to/php.log`. Users see clean pages; admins read log. To debug a specific session_start issue on production, tail the log while reproducing — no need to expose errors to user-facing pages even temporarily.
Three causes: (1) `error_reporting` excludes E_WARNING (session_start emits warnings, not errors), (2) error_log writes to a path PHP can't write to (check ownership), (3) session.save_handler set to a custom handler that silently fails. Set `error_reporting = E_ALL`, verify error_log path is writable, then reproduce.
Add `error_log("session_id before start: " . session_id());` and `error_log("session_status: " . session_status());` around session_start. session_status returns PHP_SESSION_NONE (1) or PHP_SESSION_ACTIVE (2) — if already 2, you're calling start twice. session_id() showing a value before start means cookie was read correctly.
Related articles
Fixing "Internal Server Error" (500) in Apache/Nginx
Fixing PHP session_start(): Permission Denied (13) Error
Bitrix Error Log: How to Locate, Enable, and Analyze Logs