Error: Cannot modify header information - headers already sent by

Support intro

Hello,
I installed NextcloudPi on a fresh debian installation a couple of days ago.
Everything seams to work fine. But sometimes i noticed some problems uploading files. I am not sure where they come from.

Nextcloud version: NextCloudPi 20.0.4
Operating system and version: Debian GNU/Linux 10 (buster)
Apache or nginx version:
PHP version PHP 7.3

Sometimes when I upload files to my nextcloud I encounter problems. When this happen the nextcloud is not responding for a couple of minutes.

Steps to replicate it:

  1. Just grap a couple of files from the Explorer
  2. Drag the files into the browser to upload it to the nextcloud

The output of your Nextcloud log in Admin > Logging:

[PHP] Error: Error: Cannot modify header information - headers already sent by (output started at /var/www/nextcloud/3rdparty/sabre/http/lib/Sapi.php:132) at /var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php#691 at <<closure>>

 0. <<closure>>
    OC\Log\ErrorHandler::onError(2, "Cannot modify h ... )", "/var/www/nextcl ... p", 691, {string: "X-Hash ... "})
 1. /var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php line 691
    header("X-Hash-MD5: 782 ... b")
 2. /var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php line 189
    OCA\DAV\Connector\Sabre\File->header("X-Hash-MD5: 782 ... b")
 3. <<closure>>
    OCA\DAV\Connector\Sabre\File->OCA\DAV\Connector\Sabre\{closure}("*** sensitive parameters replaced ***")
 4. /var/www/nextcloud/lib/private/Files/Stream/HashWrapper.php line 71
    call_user_func(Closure {}, "*** sensitive parameter replaced ***")
 5. <<closure>>
    OC\Files\Stream\HashWrapper->stream_close()
 6. /var/www/nextcloud/3rdparty/icewind/streams/src/Wrapper.php line 132
    fclose(null)
 7. /var/www/nextcloud/lib/private/Files/Stream/HashWrapper.php line 75
    Icewind\Streams\Wrapper->stream_close()
 8. <<closure>>
    OC\Files\Stream\HashWrapper->stream_close()
 9. /var/www/nextcloud/3rdparty/icewind/streams/src/Wrapper.php line 132
    fclose(null)
10. /var/www/nextcloud/lib/private/Files/Stream/HashWrapper.php line 75
    Icewind\Streams\Wrapper->stream_close()
11. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php line 319
    OC\Files\Stream\HashWrapper->stream_close()
12. /var/www/nextcloud/apps/dav/appinfo/v1/webdav.php line 84
    Sabre\DAV\Server->exec()
13. /var/www/nextcloud/remote.php line 167
    require_once("/var/www/nextcl ... p")

PUT /remote.php/webdav/Bilder%20und%20Videos%20f%C3%BCr%20Katrin/Urlaub%2022.April%20%202009/IMG_2549.JPG
from 185.235.59.60 by andreas at 2021-01-31T16:00:21+00:00
[no app in context] Error: Sabre\DAV\Exception\BadRequest: Expected filesize of 554458 bytes but read (from Nextcloud client) and wrote (to Nextcloud storage) 49152 bytes. Could either be a network problem on the sending side or a problem writing to the storage on the server side. at <<closure>>

0. /var/www/nextcloud/apps/dav/lib/Connector/Sabre/Directory.php line 155
   OCA\DAV\Connector\Sabre\File->put(null)
1. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php line 1104
   OCA\DAV\Connector\Sabre\Directory->createFile("IMG_2549.JPG", null)
2. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php line 527
   Sabre\DAV\Server->createFile("Bilder und Vide ... G", null, null)
3. /var/www/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php line 89
   Sabre\DAV\CorePlugin->httpPut(Sabre\HTTP\Request {}, Sabre\HTTP\Response {})
4. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php line 474
   Sabre\DAV\Server->emit("method:PUT", [Sabre\HTTP\Requ ... }])
5. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php line 251
   Sabre\DAV\Server->invokeMethod(Sabre\HTTP\Request {}, Sabre\HTTP\Response {})
6. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php line 319
   Sabre\DAV\Server->start()
7. /var/www/nextcloud/apps/dav/appinfo/v1/webdav.php line 84
   Sabre\DAV\Server->exec()
8. /var/www/nextcloud/remote.php line 167
   require_once("/var/www/nextcl ... p")

PUT /remote.php/webdav/Bilder%20und%20Videos%20f%C3%BCr%20Katrin/Urlaub%2022.April%20%202009/IMG_2549.JPG
from 185.235.59.60 by andreas at 2021-01-31T16:00:21+00:00

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'passwordsalt' => 'xxx',
  'secret' => 'xxx',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    11 => '2003:d9:ef11:e00:aaa1:59ff:fe5f:d806',
    1 => 'local ip address',
    5 => 'nextcloudpi.local',
    7 => 'nextcloudpi',
    8 => 'nextcloudpi.lan',
    20 => 'remote address',
    21 => 'local address',
    12 => 'remote address',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '20.0.4.0',
  'overwrite.cli.url' => 'remote address',
  'dbname' => 'db name',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'db nextcloud user',
  'dbpassword' => 'xxxx',
  'installed' => true,
  'instanceid' => 'och6ui2xelh5',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
    'password' => 'xxxxx',
  ),
  'tempdirectory' => '/var/www/nextcloud/data/tmp',
  'mail_smtpmode' => 'xxx',
  'mail_smtpauthtype' => 'xxx',
  'mail_from_address' => 'xxx',
  'mail_domain' => 'xxx',
  'preview_max_x' => 'xxx',
  'preview_max_y' => 'xxx',
  'jpeg_quality' => '60',
  'overwriteprotocol' => 'https',
  'mail_sendmailmode' => 'xxx',
  'mail_smtpsecure' => 'xxx',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'xxx',
  'mail_smtpport' => 'xxx',
  'mail_smtpname' => 'xxx',
  'mail_smtppassword' => 'xxxx',
);


The output of your /var/log/apache2/error.log:

[Tue Feb 02 00:00:02.171714 2021] [ssl:warn] [pid 22310:tid 140552464561280] AH$
[Tue Feb 02 00:00:02.172263 2021] [mpm_event:notice] [pid 22310:tid 14055246456$
[Tue Feb 02 00:00:02.172272 2021] [core:notice] [pid 22310:tid 140552464561280]$

Anybody any ideas what cases this problem? And how to fix this?

That is the NC version, what is your NCP version?
Can run ncp-report from terminal or ncp-config>>SYSTEM>> nc-info
How did you install it and on what hardware?

Hey Oliver,
thanks for answering and sorry for the late replay.
Hear is the nc-info:


I installed nextcloud following the instructions from ownyourbits.com for a debian installation using this:

# curl -sSL https://raw.githubusercontent.com/nextcloud/nextcloudpi/master/install.sh | bash

I’m having the same issue, very interesting in the answer. I run a rock64 ncp install, almost up to date, install via the Index of /downloads/NextCloudPi_Rock64_11-27-20/ folder.

Same here. Saw this today a lot in my log.
…Sapi.php:112) at …/Sapi.php#70

Hi, any news or solution on this topic?

Check

Is it the solution? Because i have the same issue just i add my moms iphone. With other devices or iphones i have no problems

Had the same issue after updating from NC18 to 21.

Problem was, the tmpdirectory specified in phpconfig doesn’t exist.
this line in phpconfig:
‘tempdirectory’ => ‘/var/www/nextcloud/data/tmp’,

after creating the directory with right permissions, uploads worked again :slight_smile: