Error in defining data dir in NextcloudPi

I try to define the path of my data DIR with nc-datadir.
My path is /media/myCloudDrive/ncdata which /media/myCloudDrive is = /dev/sda1 (my external usb drive)

I get this error message in return
[ nc-datadir ]
PHP Warning: fileperms(): stat failed for /media/USBdrive/ncdata/nextcloud.log in /var/www/nextcloud/lib/private/Log/File.php on line 85
{“reqId”:“6wKoQfkiGItwYmJXaFPO”,“level”:3,“time”:“2019-12-20T19:16:15+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“is_writable() expects parameter 1 to be a valid path, array given at /var/www/nextcloud/lib/private/TempManager.php#260”,“userAgent”:"–",“version”:“17.0.2.1”}
PHP Warning: fileperms(): stat failed for /media/USBdrive/ncdata/nextcloud.log in /var/www/nextcloud/lib/private/Log/File.php on line 85
{“reqId”:“6wKoQfkiGItwYmJXaFPO”,“level”:3,“time”:“2019-12-20T19:16:15+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“fileperms(): stat failed for /media/USBdrive/ncdata/nextcloud.log at /var/www/nextcloud/lib/private/Log/File.php#85”,“userAgent”:"–",“version”:“17.0.2.1”}
{“reqId”:“6wKoQfkiGItwYmJXaFPO”,“level”:2,“time”:“2019-12-20T19:16:15+00:00”,“remoteAddr”:"",“user”:"–",“app”:“no app in context”,“method”:"",“url”:"–",“message”:“Temporary directory {”/media/USBdrive/ncdata/tmp":""} is not present or writable",“userAgent”:"–",“version”:“17.0.2.1”}
PHP Warning: fileperms(): stat failed for /media/USBdrive/ncdata/nextcloud.log in /var/www/nextcloud/lib/private/Log/File.php on line 85
{“reqId”:“6wKoQfkiGItwYmJXaFPO”,“level”:3,“time”:“2019-12-20T19:16:16+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“file_get_contents(/media/USBdrive/ncdata/news/config/config.ini): failed to open stream: No such file or directory at /var/www/nextcloud/lib/private/Files/Storage/Local.php#217”,“userAgent”:"–",“version”:“17.0.2.1”}
PHP Warning: fileperms(): stat failed for /media/USBdrive/ncdata/nextcloud.log in /var/www/nextcloud/lib/private/Log/File.php on line 85
{“reqId”:“6wKoQfkiGItwYmJXaFPO”,“level”:3,“time”:“2019-12-20T19:16:16+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“fileperms(): stat failed for /media/USBdrive/ncdata/nextcloud.log at /var/www/nextcloud/lib/private/Log/File.php#85”,“userAgent”:"–",“version”:“17.0.2.1”}
{“reqId”:“6wKoQfkiGItwYmJXaFPO”,“level”:2,“time”:“2019-12-20T19:16:16+00:00”,“remoteAddr”:"",“user”:"–",“app”:“news”,“method”:"",“url”:"–",“message”:“Configuration invalid. Ignoring values.”,“userAgent”:"–",“version”:“17.0.2.1”}
PHP Warning: fileperms(): stat failed for /media/USBdrive/ncdata/nextcloud.log in /var/www/nextcloud/lib/private/Log/File.php on line 85
{“reqId”:“6wKoQfkiGItwYmJXaFPO”,“level”:3,“time”:“2019-12-20T19:16:16+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“mkdir(): Permission denied at /var/www/nextcloud/apps/news/lib/AppInfo/Application.php#141”,“userAgent”:"–",“version”:“17.0.2.1”}
PHP Warning: fileperms(): stat failed for /media/USBdrive/ncdata/nextcloud.log in /var/www/nextcloud/lib/private/Log/File.php on line 85
{“reqId”:“6wKoQfkiGItwYmJXaFPO”,“level”:3,“time”:“2019-12-20T19:16:16+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“fopen(/media/USBdrive/ncdata/data_dir_writability_test_5dfd1e006d2ec.tmp): failed to open stream: Permission denied at /var/www/nextcloud/lib/private/legacy/util.php#796”,“userAgent”:"–",“version”:“17.0.2.1”}
PHP Warning: fileperms(): stat failed for /media/USBdrive/ncdata/nextcloud.log in /var/www/nextcloud/lib/private/Log/File.php on line 85
{“reqId”:“6wKoQfkiGItwYmJXaFPO”,“level”:3,“time”:“2019-12-20T19:16:16+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“fileperms(): stat failed for /media/USBdrive/ncdata/nextcloud.log at /var/www/nextcloud/lib/private/Log/File.php#85”,“userAgent”:"–",“version”:“17.0.2.1”}
{“reqId”:“6wKoQfkiGItwYmJXaFPO”,“level”:3,“time”:“2019-12-20T19:16:16+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“chmod(): No such file or directory at /var/www/nextcloud/lib/private/Log/File.php#86”,“userAgent”:"–",“version”:“17.0.2.1”}
Error reading data directory. Is NextCloud running and configured?

[ nc-scan-auto ]
Your data directory is invalid
Ensure there is a file called “.ocdata” in the root of the data directory.

Your data directory is not writable
Permissions can usually be fixed by giving the webserver write access to the root directory. See https://docs.nextcloud.com/server/17/go.php?to=admin-dir_permissions.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:166
Stack trace:
#0 /var/www/nextcloud/console.php(96): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /var/www/nextcloud/occ(11): require_once(’/var/www/nextcl
’)
#2 {main}

[ nc-scan-auto ]
Your data directory is invalid
Ensure there is a file called “.ocdata” in the root of the data directory.

Your data directory is not writable
Permissions can usually be fixed by giving the webserver write access to the root directory. See https://docs.nextcloud.com/server/17/go.php?to=admin-dir_permissions.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:166
Stack trace:
#0 /var/www/nextcloud/console.php(96): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /var/www/nextcloud/occ(11): require_once(’/var/www/nextcl
’)
#2 {main}

An idea how to correct this ?

I have not “.ocdata” in the root of the data directory. What is this file ? Where can I find it ? What is this structure or format ?

Thank you.

.ocdata is a hidden folder.

ls -a /path/to/folder/

will reveal hidden files and folders in Linux.

default for .ocdata is

ls -a /var/www/nextcloud/

yours would become /media/myCloudDrive/ncdata/
if it’s formatted and mounted correctly.
How did you format and mount?

OK I correct my path because, my ncdata was renamed with a date in the name of file and an empty ncdata directory was created instead.
Now it’s Ok, but I have an othe problem with log:

The datadir contains:

root@nextcloudpi:/media/myCloudDrive/ncdata# ls -al
total 12208
drwxr-x— 1 www-data www-data 378 dĂ©c. 22 16:44 .
drwxr-xr-x 1 root root 290 déc. 22 16:46 

drwxr-xr-x 1 www-data www-data 154 déc. 19 21:00 appdata_ockubejeb23o
-rw-r----- 1 www-data www-data 907 déc. 19 20:57 audit.log
drwxr-xr-x 1 www-data www-data 26 déc. 19 20:56 files_external
drwxr-xr-x 1 www-data www-data 0 déc. 18 2018 __groupfolders
-rw-r–r-- 1 www-data www-data 324 dĂ©c. 20 06:56 .htaccess
-rw-r–r-- 1 www-data www-data 0 dĂ©c. 20 06:56 index.html
drwxr-xr-x 1 www-data www-data 90 août 7 18:02 ncp
drwxr-xr-x 1 www-data www-data 1276 déc. 20 06:57 ncp-update-backups
drwxr-xr-x 1 www-data www-data 22 nov. 23 2018 news
-rw-r----- 1 www-data www-data 12458466 déc. 22 16:55 nextcloud.log
-rw-r–r-- 1 www-data www-data 0 dĂ©c. 20 06:56 .ocdata
drwxr-xr-x 1 www-data www-data 576 août 10 06:26 .opcache
drwxrwxr-x 1 www-data www-data 0 déc. 20 08:46 tmp
-rw-r–r-- 1 www-data www-data 12665 mars 2 2019 updater.log
drwxr-xr-x 1 www-data www-data 74 mars 2 2019 updater-ockubejeb23o
root@nextcloudpi:/media/myCloudDrive/ncdata# cd tmp
root@nextcloudpi:/media/myCloudDrive/ncdata/tmp# ls -al
total 0
drwxrwxr-x 1 www-data www-data 0 déc. 20 08:46 .
drwxr-x— 1 www-data www-data 378 dĂ©c. 22 16:44 

root@nextcloudpi:/media/myCloudDrive/ncdata/tmp#

and my log contains the following errors messages ( 4 messages by a second !)
Warning no app in context Temporary directory {"/media/USBdrive/ncdata/tmp":""} is not present or writable
2019-12-22T16:51:09+0100
Error PHP is_writable() expects parameter 1 to be a valid path, array given at /var/www/nextcloud/lib/private/TempManager.php#260
2019-12-22T16:51:09+0100

However my tmp directory is well present with the rights for www-data !!!

An idea of the problem ?
Thanks

check value of sys_temp_dir
in
/etc/php/7.3/fpm/php.ini

see "HEADERS on invalid stream"

In th php.ini, it’s not fixed, so the default value must be use ?

; Directory where the temporary files should be placed.
; Defaults to the system default (see sys_get_temp_dir)
;sys_temp_dir = “/tmp”

May I overide this value with “/media/myCloudDrive/ncdata/tmp”, but in this case I’ll get surely the same error ?

Yes, That would fix the issue, afaik.
Note : You should also remove the “;” at start of that line and run sudo restart php7.3-fpm.service.

OliverV, I tried your solution
Unfortunately, this doesn’t correct the problem and now I have one error message in supplment every second, so all the seconds I have 3 errors/warning messages in log file:

[no app in context] Warning: Temporary directory /media/myClouDrive/ncdata/tmp is not present or writable

[no app in context] Warning: Temporary directory {"/media/USBdrive/ncdata/tmp":""} is not present or writable

[PHP] Error: is_writable() expects parameter 1 to be a valid path, array given at /var/www/nextcloud/lib/private/TempManager.php#260

Path to datadir and tmp are also defined in

/var/www/nextcloud/config/config.php

So you should check and edit the value of

‘datadirectory’ =>
‘tempdirectory’ =>

to point to the actual ncdata and tmp directories.

The paths and directories to “/media/myCloudDrive/ncdata/tmp” was already OK for the 2 parameters in config.php.
The problem in the log is always present.

I’ve looked at the rights of “/media/myCloudDrive/ncdata/tmp”
Just the flag “write for others” was not active.
I modify this flag with “chmod o+w tmp” but the problem in the log continues.
The rights are now:
drwxrwxrwx 1 www-data www-data 0 déc. 22 20:24 tmp

Very strange this permanent error in log.
The errors continues to be:

[no app in context] Warning: Temporary directory {"/media/myCloudDrive/ncdata/tmp":""} is not present or writable
GET /index.php/apps/logreader/poll?lastReqId=XgZLOOV%40vH4%40NAEBl-jNhwAACBA
from 192.168.0.19 by ncp at 2019-12-27T18:19:37+00:00

and

[PHP] Error: is_writable() expects parameter 1 to be a valid path, array given at /var/www/nextcloud/lib/private/TempManager.php#260

GET /index.php/apps/logreader/poll?lastReqId=XgZLOOV%40vH4%40NAEBl-jNhwAACBA
from 192.168.0.19 by ncp at 2019-12-27T18:19:37+00:00

your first error message seems to indicate that you had an incorrect datadir to start with so NCP never moved it