Sync failed failed to open stream: Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php

Nextcloud version : 13.0.4.0
Operating system and version : Debian 9 on virtualbox

PHP version : 7.1

The issue you are facing:
Firstly, files from mobile app failed to auto-upload (bad request). When I checked logs, I found multiple issues with permissions.
I checked permissions, now they are set to root:root, 644. (I checked my old working Rasberry pi nextcloud instance, there is the same permissions.
UPD: trashbine and versioning doesn’t work too.

Is this the first time you’ve seen this error? (Y/N): Yes

Steps to replicate it: Installed following standard guide:
$ sudo mv latest.zip /var/www/html*
$ cd /var/www/html
$ sudo unzip -q latest.zip

The output of your Nextcloud log in Admin > Logging:

|Error|core|unable to rename, destination directory is not writable : files_trashbin/files|2018-07-15T10:36:42+0200|
|---|---|---|---|
|Error|PHP|unlink(/nextcloud/disk1/nextcloud/data//userhome/files_versions/Other/test.mkv.v1527959732): Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#225|2018-07-15T10:36:16+0200|
|Error|PHP|unlink(/nextcloud/disk1/nextcloud/data//userhome/files_versions/Other/test.mkv.v1529334857): Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#225|2018-07-15T10:36:16+0200|
|Error|PHP|unlink(/nextcloud/disk1/nextcloud/data//userhome/files_versions/Other/test.mkv.v1530718586): Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#225|2018-07-15T10:36:16+0200|
|Error|PHP|unlink(/nextcloud/disk1/nextcloud/data//userhome/files_versions/Other/test.mkv.v1530807178): Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#225|2018-07-15T10:36:16+0200|
|Error|PHP|unlink(/nextcloud/disk1/nextcloud/data//userhome/files_versions/Other/test.mkv.v1530745572): Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#225|2018-07-15T10:36:16+0200|
|Error|core|unable to rename, source directory is not writable : files_external|2018-07-15T10:30:43+0200|
|Error|PHP|fclose() expects parameter 1 to be resource, boolean given at /var/www/html/nextcloud/lib/private/Security/CertificateManager.php#157|2018-07-15T10:30:43+0200|
|Error|PHP|fwrite() expects parameter 1 to be resource, boolean given at /var/www/html/nextcloud/lib/private/Security/CertificateManager.php#148|2018-07-15T10:30:43+0200|
|Error|PHP|fopen(/nextcloud/disk1/nextcloud/data/files_external/rootcerts.crt.tmp7271097619): failed to open stream: Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#282|2018-07-15T10:30:43+0200|
|Error|core|unable to rename, source directory is not writable : files_external|2018-07-15T10:30:40+0200|
|Error|PHP|fclose() expects parameter 1 to be resource, boolean given at /var/www/html/nextcloud/lib/private/Security/CertificateManager.php#157|2018-07-15T10:30:40+0200|
|Error|PHP|fwrite() expects parameter 1 to be resource, boolean given at /var/www/html/nextcloud/lib/private/Security/CertificateManager.php#148|2018-07-15T10:30:40+0200|
|Error|PHP|fopen(/nextcloud/disk1/nextcloud/data/files_external/rootcerts.crt.tmp0532623373): failed to open stream: Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#282|2018-07-15T10:30:40+0200|
|Fatal|webdav|Sabre\DAV\Exception\BadRequest: expected filesize 1024000 got 0|2018-07-15T10:00:00+0200|
|Error|PHP|fopen(/nextcloud/disk1/nextcloud/data//userhome/cache/IMG_20180706_132157.jpg-chunking-320604985-0.YwdKi9EcN4TmtsLv.part): failed to open stream: Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#282|2018-07-15T10:00:00+0200|
|Fatal|webdav|Sabre\DAV\Exception\BadRequest: expected filesize 1024000 got 0|2018-07-15T09:59:59+0200|

On client side (win 10):

 15.07.2018 23:17:26,                                                    Untitled.pdf,            D:\Multimedia\Temp,The item is not synced because of previous errors: Error transferring https://cloud.proeml.com/remote.php/dav/files/userhome/Temp/Untitled.pdf - server replied: Forbidden (Sabre\DAV\Exception\Forbidden)
 15.07.2018 23:17:22,Grim Dawn/save/user/_Char1/levels_world001.map/Normal/quests.gdd.bak,               D:\Games\_saves,Connection closed
 15.07.2018 23:17:10,                                                    Untitled.pdf,           D:\Multimedia\Other,The item is not synced because of previous errors: Error transferring https://cloud.proeml.com/remote.php/dav/files/userhome/Other/Untitled.pdf - server replied: Forbidden
 15.07.2018 23:17:10,                                                   Leningrad.mkv,           D:\Multimedia\Other,The item is not synced because of previous errors: Error transferring https://dav/uploads/userhome/390182332/.file - server replied: Forbidden (Sabre\DAV\Exception\Forbidden)
 15.07

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

<?php
$CONFIG = array (
  'instanceid' => '_______',
  'passwordsalt' => '______',
  'secret' => '______',
  'trusted_domains' => 
  array (
    0 => '192.168.1.99',
  ),
  'datadirectory' => '/nextcloud/disk1/nextcloud/data/',
  'overwrite.cli.url' => 'http://192.168.1.99/nextcloud',
  'dbtype' => 'mysql',
  'version' => '13.0.4.0',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'user',
  'dbpassword' => '________',
  'installed' => true,
  
  'allow_user_to_change_display_name' => true,
  'remember_login_cookie_lifetime' => 1296000,
  'session_lifetime' => 1800,
  'trashbin_retention_obligation' => 10,
  0 => 20,
  'versions_retention_obligation' => 'auto,5',
  'check_for_working_htaccess' => true,
  'config_is_read_only' => false,
  'enable_previews' => true,
  'maintenance' => false,
  'updater.secret' => '_________',
  'theme' => '',
  'loglevel' => 2,
  'auth.bruteforce.protection.enabled' => true,
  'integrity.check.disabled' => true,
);

Kind regards.

…set to root …

this is your problem. They need to be set to www-data or any users running nextcloud whithin the www/html definition, not root.

1 Like

Doesn’t worked :confused:
Only one solution by now worked for me is to delete user and to recreate a new one. Than all sync works fine.
And that not a good one if I restore db from backup and need to resync all data, including contacts and calendar.

Hi,
I just had a similar problem with similar errors in the log.
With my installation it helped to check and correct the user and group ownership of the directory files_external in the data directory. For whatever reason these didn’t match the right ones for my installation.
Hope this helps you too!

Didn’t got you :slight_smile: