Internal Server Error: Headers already sent, cannot change session name

Hello kind stranger! I appreciate any help to get my cloud running again!

My nextcloud instance is not reachable and I am stuck with an Internal Server Error that will show when I request webpages with the browser. For each access the nextcloud log shows errors with the following messages:

ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at /var/www/html/nextcloud/lib/base.php#402

and

session_name(): Cannot change session name when headers already sent

What I did before this occured

I wanted to see if uploading more files would lead to the removal of old deleted files in the trashbin.

I did:

  • upload 2GB of images and deleting them (before they were fully uploaded)
  • change config.php to include 'trashbin_retention_obligation' => 'auto, 30',

connected via ssh, I could see that the trash folder reduced drastically in size. Hurray! :partying_face:

But the nextcloud service was not working anymore :hot_face:

config.php:

nextcloud/config/config.php
 <?php
$CONFIG = array (
  'instanceid' => 'xxxxxxxxxxxxxx',
  'passwordsalt' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'trusted_domains' =>
  array (
    0 => 'xxxxxxxxxxxxxx',
  ),
  'datadirectory' => '/var/www/html/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '21.0.1.1',
  'overwrite.cli.url' => 'xxxxxxxxxxxxxx',
  'dbname' => 'xxxxxxxx',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextuser',
  'dbpassword' => 'xxxxxxxxxxxxxx',
  'installed' => true,
  'maintenance' => false,
  'trashbin_retention_obligation' => 'auto, 30',
);

nextcloud log

# excerpt with reqId matching the ID shown on the webpage after a request 
{"reqId":"AUg5EjWGgGmMZIFsuuzH","level":3,"time":"2022-05-07T11:57:17+00:00","remoteAddr":"176.199.209.27","user":"--","app":"PHP","method":"GET","url":"/nextcloud/","message":{"Exception":"Error","Message":"ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at /var/www/html/nextcloud/lib/base.php#402","Code":0,"Trace":[{"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::","args":[2,"ini_set(): Headers already sent. You cannot change the session module's ini settings at this time","/var/www/html/nextcloud/lib/base.php",402,[]]},{"file":"/var/www/html/nextcloud/lib/base.php","line":402,"function":"ini_set","args":["session.cookie_secure","1"]},{"file":"/var/www/html/nextcloud/lib/base.php","line":639,"function":"initSession","class":"OC","type":"::","args":[]},{"file":"/var/www/html/nextcloud/lib/base.php","line":1076,"function":"init","class":"OC","type":"::","args":[]},{"file":"/var/www/html/nextcloud/index.php","line":35,"args":["/var/www/html/nextcloud/lib/base.php"],"function":"require_once"}],"File":"/var/www/html/nextcloud/lib/private/Log/ErrorHandler.php","Line":92,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0","version":"21.0.1.1"}
{"reqId":"AUg5EjWGgGmMZIFsuuzH","level":3,"time":"2022-05-07T11:57:17+00:00","remoteAddr":"176.199.209.27","user":"--","app":"PHP","method":"GET","url":"/nextcloud/","message":{"Exception":"Error","Message":"ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at /var/www/html/nextcloud/lib/base.php#406","Code":0,"Trace":[{"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::","args":[2,"ini_set(): Headers already sent. You cannot change the session module's ini settings at this time","/var/www/html/nextcloud/lib/base.php",406,[]]},{"file":"/var/www/html/nextcloud/lib/base.php","line":406,"function":"ini_set","args":["session.cookie_httponly","true"]},{"file":"/var/www/html/nextcloud/lib/base.php","line":639,"function":"initSession","class":"OC","type":"::","args":[]},{"file":"/var/www/html/nextcloud/lib/base.php","line":1076,"function":"init","class":"OC","type":"::","args":[]},{"file":"/var/www/html/nextcloud/index.php","line":35,"args":["/var/www/html/nextcloud/lib/base.php"],"function":"require_once"}],"File":"/var/www/html/nextcloud/lib/private/Log/ErrorHandler.php","Line":92,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0","version":"21.0.1.1"}
{"reqId":"AUg5EjWGgGmMZIFsuuzH","level":3,"time":"2022-05-07T11:57:17+00:00","remoteAddr":"176.199.209.27","user":"--","app":"PHP","method":"GET","url":"/nextcloud/","message":{"Exception":"Error","Message":"ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at /var/www/html/nextcloud/lib/base.php#410","Code":0,"Trace":[{"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::","args":[2,"ini_set(): Headers already sent. You cannot change the session module's ini settings at this time","/var/www/html/nextcloud/lib/base.php",410,{"cookie_path":"/nextcloud"}]},{"file":"/var/www/html/nextcloud/lib/base.php","line":410,"function":"ini_set","args":["session.cookie_path","/nextcloud"]},{"file":"/var/www/html/nextcloud/lib/base.php","line":639,"function":"initSession","class":"OC","type":"::","args":[]},{"file":"/var/www/html/nextcloud/lib/base.php","line":1076,"function":"init","class":"OC","type":"::","args":[]},{"file":"/var/www/html/nextcloud/index.php","line":35,"args":["/var/www/html/nextcloud/lib/base.php"],"function":"require_once"}],"File":"/var/www/html/nextcloud/lib/private/Log/ErrorHandler.php","Line":92,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0","version":"21.0.1.1"}
{"reqId":"AUg5EjWGgGmMZIFsuuzH","level":3,"time":"2022-05-07T11:57:17+00:00","remoteAddr":"176.199.209.27","user":"--","app":"base","method":"GET","url":"/nextcloud/","message":{"Exception":"ErrorException","Message":"session_name(): Cannot change session name when headers already sent","Code":0,"Trace":[{"function":"trapError","class":"OC\\Session\\Internal","type":"->","args":[2,"session_name(): Cannot change session name when headers already sent","/var/www/html/nextcloud/lib/private/Session/Internal.php",209,{"functionName":"session_name","parameters":["occbjyfmd6fo"],"silence":false}]},{"function":"session_name","args":["occbjyfmd6fo"]},{"file":"/var/www/html/nextcloud/lib/private/Session/Internal.php","line":209,"function":"call_user_func_array","args":["session_name",["occbjyfmd6fo"]]},{"file":"/var/www/html/nextcloud/lib/private/Session/Internal.php","line":55,"function":"invoke","class":"OC\\Session\\Internal","type":"->","args":["session_name",["occbjyfmd6fo"]]},{"file":"/var/www/html/nextcloud/lib/base.php","line":417,"function":"__construct","class":"OC\\Session\\Internal","type":"->","args":["occbjyfmd6fo"]},{"file":"/var/www/html/nextcloud/lib/base.php","line":639,"function":"initSession","class":"OC","type":"::","args":[]},{"file":"/var/www/html/nextcloud/lib/base.php","line":1076,"function":"init","class":"OC","type":"::","args":[]},{"file":"/var/www/html/nextcloud/index.php","line":35,"args":["/var/www/html/nextcloud/lib/base.php"],"function":"require_once"}],"File":"/var/www/html/nextcloud/lib/private/Session/Internal.php","Line":185,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0","version":"21.0.1.1"}

Versions

Nextcloud version : 21.0.1.1
Apache 2.4.38 (Debian)
Server built: 2021-12-21


Currently, nextcloud is offline and the webpage just reads

Internal Server Error

The server was unable to complete your request.

If this happens again, please send the technical details below to the server administrator.

More details can be found in the server log.
Technical details

Remote Address: <myip>
Request ID: AUg5EjWGgGmMZIFsuuzH

I would be very grateful if you could help me with untangeling my problem! My workflow is severly impaired since my devices don’t sync files and calendar anymore, so I hope to resolve this soon.

Do you have a backup you can restore?

You can search your errors as keywords on the forum, internet and documentation to find ways to resolve your problem.

Example:

https://help.nextcloud.com/search?q=/var/www/html/nextcloud/lib/private/Log/ErrorHandler.php

I unfortunately don’t have an backup of the server. I do have the files though.

Searching for “session module ini settings change” I found this similar recent issue (that no one replied to :confused: )

I added a short explanation of the meaning of “Headers already sent” at Error","Message":"ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at - #2 by holi