Error: Your data directory is not writable

Nextcloud version: 16.0.5.1
Operating system and version: Raspbian GNU/Linux 9 (stretch)
Apache or nginx version: ?
PHP version (eg, 7.1): 7.2.24-1

Hello, this week I have been facing the following issue when trying to access my nextcloud:

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/16/go.php?to=admin- 
dir_permissions.

When I go to the stated website I cannot find any helpful information to fix this issue. I haven’t done anything to my nextcloud in the past week.

Another weird issue is that I cannot check on my apache version via httpd -version or apachectl status. For the last comment this is the output:

pi@nextcloudpi:/etc $ apachectl status
/usr/sbin/apachectl: 113: /usr/sbin/apachectl: www-browser: not found
'www-browser -dump http://localhost:80/server-status' failed.
Maybe you need to install a package providing www-browser or you
need to adjust the APACHE_LYNX variable in /etc/apache2/envvars

The output of ncp-report:

NextCloudPi diagnostics

Cannot load Zend OPcache - it was already loaded
{"reqId":"2jWn7c7JndQH4juf8R87","level":2,"time":"2019-11-10T12:51:49+00:00","re                                                                                                                                                                                               moteAddr":"","user":"--","app":"no app in context","method":"","url":"--","messa                                                                                                                                                                                               ge":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writ                                                                                                                                                                                               able","userAgent":"--","version":"16.0.5.1"}

{"reqId":"2jWn7c7JndQH4juf8R87","level":3,"time":"2019-11-10T12:51:51+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/data_dir_writability_test_5dc807e76c5f0.tmp): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/legacy\/util.php#796","userAgent":"--","version":"16.0.5.1"}
{"reqId":"2jWn7c7JndQH4juf8R87","level":3,"time":"2019-11-10T12:51:51+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/nextcloud.log): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/Log\/File.php#139","userAgent":"--","version":"16.0.5.1"}
NextCloudPi version  v1.13.6
NextCloudPi image    NextCloudPi_11-22-18
distribution         Raspbian GNU/Linux 9 \n \l
automount            yes
USB devices          sda sdb
datadir              /media/USBdrive1/ncdata
data in SD           no
data filesystem      btrfs
data disk usage      23G/30G
rootfs usage         2.3G/15G
swapfile             /var/swap
dbdir                /media/USBdrive/ncdatabase
Nextcloud check      error
HTTPD service        up
PHP service          up
MariaDB service      up
Redis service        up
Postfix service      up
internet check       ok
port check 80        open
port check 443       open
IP                   ***REMOVED SENSITIVE VALUE***
gateway              ***REMOVED SENSITIVE VALUE***
interface            eth0
certificates         ***REMOVED SENSITIVE VALUE***
NAT loopback         no
uptime               51min

Nextcloud configuration

Cannot load Zend OPcache - it was already loaded
{"reqId":"5FrkPfjd0Rg4zLEKOyya","level":2,"time":"2019-11-10T12:51:57+00:00","remoteAddr":"","user":"--","app":"no app in context","method":"","url":"--","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"--","version":"16.0.5.1"}
{"reqId":"5FrkPfjd0Rg4zLEKOyya","level":3,"time":"2019-11-10T12:51:59+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/data_dir_writability_test_5dc807ef43a15.tmp): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/legacy\/util.php#796","userAgent":"--","version":"16.0.5.1"}
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/16/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}{"reqId":"5FrkPfjd0Rg4zLEKOyya","level":3,"time":"2019-11-10T12:51:59+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/nextcloud.log): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/Log\/File.php#139","userAgent":"--","version":"16.0.5.1"}

HTTPd logs

[Fri Nov 08 22:30:07.456200 2019] [mpm_event:notice] [pid 912:tid 1996136688] AH00491: caught SIGTERM, shutting down
[Fri Nov 08 22:30:26.041671 2019] [ssl:warn] [pid 586:tid 1995571440] AH01909: localhost:4443:0 server certificate does NOT include an ID which matches the server name
[Fri Nov 08 22:30:27.133726 2019] [ssl:warn] [pid 871:tid 1995571440] AH01909: localhost:4443:0 server certificate does NOT include an ID which matches the server name
[Fri Nov 08 22:30:28.006981 2019] [mpm_event:notice] [pid 871:tid 1995571440] AH00489: Apache/2.4.25 (Raspbian) OpenSSL/1.0.2t configured -- resuming normal operations
[Fri Nov 08 22:30:28.007369 2019] [core:notice] [pid 871:tid 1995571440] AH00094: Command line: '/usr/sbin/apache2'
[Sat Nov 09 22:30:02.519544 2019] [mpm_event:notice] [pid 871:tid 1995571440] AH00491: caught SIGTERM, shutting down
[Sat Nov 09 22:30:20.475068 2019] [ssl:warn] [pid 605:tid 1996259568] AH01909: localhost:4443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 22:30:21.111107 2019] [ssl:warn] [pid 937:tid 1996259568] AH01909: localhost:4443:0 server certificate does NOT include an ID which matches the server name
[Sat Nov 09 22:30:22.006290 2019] [mpm_event:notice] [pid 937:tid 1996259568] AH00489: Apache/2.4.25 (Raspbian) OpenSSL/1.0.2t configured -- resuming normal operations
[Sat Nov 09 22:30:22.006771 2019] [core:notice] [pid 937:tid 1996259568] AH00094: Command line: '/usr/sbin/apache2'
[Sun Nov 10 12:13:35.855281 2019] [proxy_fcgi:error] [pid 970:tid 1775313968] [client 192.168.178.54:50863] AH01071: Got error 'PHP message: PHP Notice:  Undefined index: app in /var/www/ncp-web/index.php on line 238\nPHP message: PHP Notice:  Undefined index: app in /var/www/ncp-web/index.php on line 244\n'
[Sun Nov 10 12:59:48.652113 2019] [proxy_fcgi:error] [pid 970:tid 1766921264] [client 192.168.178.54:50863] AH01067: Failed to read FastCGI header
[Sun Nov 10 12:59:48.689578 2019] [proxy_fcgi:error] [pid 970:tid 1766921264] (104)Connection reset by peer: [client 192.168.178.54:50863] AH01075: Error dispatching request to :4443:
[Sun Nov 10 12:59:49.659249 2019] [mpm_event:notice] [pid 937:tid 1996259568] AH00491: caught SIGTERM, shutting down
[Sun Nov 10 13:00:06.616331 2019] [ssl:warn] [pid 584:tid 1996411120] AH01909: localhost:4443:0 server certificate does NOT include an ID which matches the server name
[Sun Nov 10 13:00:07.138087 2019] [ssl:warn] [pid 844:tid 1996411120] AH01909: localhost:4443:0 server certificate does NOT include an ID which matches the server name
[Sun Nov 10 13:00:08.006654 2019] [mpm_event:notice] [pid 844:tid 1996411120] AH00489: Apache/2.4.25 (Raspbian) OpenSSL/1.0.2t configured -- resuming normal operations
[Sun Nov 10 13:00:08.007067 2019] [core:notice] [pid 844:tid 1996411120] AH00094: Command line: '/usr/sbin/apache2'
[Sun Nov 10 13:01:12.517451 2019] [proxy_fcgi:error] [pid 900:tid 1926534192] [client 192.168.178.54:58486] AH01067: Failed to read FastCGI header
[Sun Nov 10 13:01:12.517701 2019] [proxy_fcgi:error] [pid 900:tid 1926534192] (104)Connection reset by peer: [client 192.168.178.54:58486] AH01075: Error dispatching request to :4443:

Database logs

2019-11-10 13:01:08 1989066544 [Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffer pool size. In order to use backoff, increase buffer pool at least up to 20MB.

2019-11-10 13:01:08 1989066544 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2019-11-10 13:01:08 1989066544 [Note] InnoDB: The InnoDB memory heap is disabled
2019-11-10 13:01:08 1989066544 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-11-10 13:01:08 1989066544 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2019-11-10 13:01:08 1989066544 [Note] InnoDB: Compressed tables use zlib 1.2.8
2019-11-10 13:01:08 1989066544 [Note] InnoDB: Using Linux native AIO
2019-11-10 13:01:08 1989066544 [Note] InnoDB: Using generic crc32 instructions
2019-11-10 13:01:08 1989066544 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-11-10 13:01:08 1989066544 [Note] InnoDB: Completed initialization of buffer pool
2019-11-10 13:01:08 1989066544 [Note] InnoDB: Highest supported file format is Barracuda.
2019-11-10 13:01:08 1989066544 [Note] InnoDB: 128 rollback segment(s) are active.
2019-11-10 13:01:08 1989066544 [Note] InnoDB: Waiting for purge to start
2019-11-10 13:01:08 1989066544 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.42-84.2 started; log sequence number 2050072394
2019-11-10 13:01:08 1384117056 [Note] InnoDB: Dumping buffer pool(s) not yet started
2019-11-10 13:01:08 1989066544 [Note] Plugin 'FEEDBACK' is disabled.
2019-11-10 13:01:08 1989066544 [Note] Server socket created on IP: '127.0.0.1'.
2019-11-10 13:01:08 1989066544 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.1.38-MariaDB-0+deb9u1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  Raspbian 9.0

Nextcloud logs

{"reqId":"XcfuKH8AAQEAAAPJzycAABYB","level":2,"time":"2019-11-10T11:02:00+00:00","remoteAddr":"79.233.152.230","user":"mira","app":"no app in context","method":"GET","url":"\/ocs\/v2.php\/apps\/notifications\/api\/v2\/notifications","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko\/20100101 Firefox\/70.0","version":"16.0.5.1"}
{"reqId":"XcfwEH8AAQEAAAPKXP8AAEkY","level":2,"time":"2019-11-10T11:10:08+00:00","remoteAddr":"79.199.41.191","user":"--","app":"no app in context","method":"GET","url":"\/status.php","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwEH8AAQEAAAPJzygAABcA","level":2,"time":"2019-11-10T11:10:08+00:00","remoteAddr":"79.199.41.191","user":"--","app":"no app in context","method":"GET","url":"\/status.php","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwEH8AAQEAAAPKXQAAAEkY","level":2,"time":"2019-11-10T11:10:08+00:00","remoteAddr":"79.199.41.191","user":"--","app":"no app in context","method":"PROPFIND","url":"\/remote.php\/webdav\/","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwEH8AAQEAAAPJzykAABcA","level":2,"time":"2019-11-10T11:10:08+00:00","remoteAddr":"79.199.41.191","user":"--","app":"no app in context","method":"PROPFIND","url":"\/remote.php\/webdav\/","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwGX8AAQEAAAPKXQEAAEgY","level":2,"time":"2019-11-10T11:10:17+00:00","remoteAddr":"79.199.41.191","user":"ncp","app":"no app in context","method":"GET","url":"\/ocs\/v1.php\/cloud\/capabilities?format=json","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwGX8AAQEAAAPJzysAAA4B","level":2,"time":"2019-11-10T11:10:17+00:00","remoteAddr":"79.199.41.191","user":"andi","app":"no app in context","method":"GET","url":"\/ocs\/v1.php\/config?format=json","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwGX8AAQEAAAPKXQIAAEgE","level":2,"time":"2019-11-10T11:10:18+00:00","remoteAddr":"79.199.41.191","user":"ncp","app":"no app in context","method":"GET","url":"\/ocs\/v1.php\/config?format=json","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwGX8AAQEAAAPJzyoAAA4A","level":2,"time":"2019-11-10T11:10:18+00:00","remoteAddr":"79.199.41.191","user":"andi","app":"no app in context","method":"GET","url":"\/ocs\/v1.php\/cloud\/capabilities?format=json","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwGn8AAQEAAAPKXQMAAEgY","level":2,"time":"2019-11-10T11:10:18+00:00","remoteAddr":"79.199.41.191","user":"ncp","app":"no app in context","method":"GET","url":"\/ocs\/v1.php\/cloud\/user?format=json","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwGn8AAQEAAAPJzywAABEA","level":2,"time":"2019-11-10T11:10:18+00:00","remoteAddr":"79.199.41.191","user":"andi","app":"no app in context","method":"GET","url":"\/ocs\/v1.php\/cloud\/user?format=json","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwGn8AAQEAAAPKXQQAAE4Y","level":2,"time":"2019-11-10T11:10:18+00:00","remoteAddr":"79.199.41.191","user":"ncp","app":"no app in context","method":"GET","url":"\/remote.php\/dav\/avatars\/ncp\/128.png","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwG38AAQEAAAPJzy0AAAwA","level":2,"time":"2019-11-10T11:10:19+00:00","remoteAddr":"79.199.41.191","user":"andi","app":"no app in context","method":"GET","url":"\/remote.php\/dav\/avatars\/andi\/128.png","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwG38AAQEAAAPKXQYAAEcE","level":2,"time":"2019-11-10T11:10:19+00:00","remoteAddr":"79.199.41.191","user":"ncp","app":"no app in context","method":"GET","url":"\/ocs\/v2.php\/apps\/notifications\/api\/v2\/notifications?format=json","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwG38AAQEAAAPKXQUAAEcY","level":2,"time":"2019-11-10T11:10:19+00:00","remoteAddr":"79.199.41.191","user":"ncp","app":"no app in context","method":"GET","url":"\/ocs\/v2.php\/cloud\/activity?start=0&count=100&format=json","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwG38AAQEAAAPJzy8AAAEB","level":2,"time":"2019-11-10T11:10:19+00:00","remoteAddr":"79.199.41.191","user":"andi","app":"no app in context","method":"GET","url":"\/ocs\/v2.php\/apps\/notifications\/api\/v2\/notifications?format=json","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwG38AAQEAAAPKXQYAAEcE","level":3,"time":"2019-11-10T11:10:19+00:00","remoteAddr":"79.199.41.191","user":"ncp","app":"no app in context","method":"GET","url":"\/ocs\/v2.php\/apps\/notifications\/api\/v2\/notifications?format=json","message":{"Exception":"Symfony\\Component\\Routing\\Exception\\RouteNotFoundException","Message":"Unable to generate a URL for the named route \"ocs.provisioning_api.AppsController.disable\" as such route does not exist.","Code":0,"Trace":[{"file":"\/var\/www\/nextcloud\/lib\/private\/Route\/Router.php","line":337,"function":"generate","class":"Symfony\\Component\\Routing\\Generator\\UrlGenerator","type":"->","args":["ocs.provisioning_api.AppsController.disable",{"app":"nextcloud_announcements"},1]},{"file":"\/var\/www\/nextcloud\/lib\/private\/Route\/CachingRouter.php","line":60,"function":"generate","class":"OC\\Route\\Router","type":"->","args":["ocs.provisioning_api.AppsController.disable",{"app":"nextcloud_announcements"},false]},{"file":"\/var\/www\/nextcloud\/lib\/private\/URLGenerator.php","line":95,"function":"generate","class":"OC\\Route\\CachingRouter","type":"->","args":["ocs.provisioning_api.AppsController.disable",{"app":"nextcloud_announcements"},false]},{"file":"\/var\/www\/nextcloud\/apps\/nextcloud_announcements\/lib\/Notification\/Notifier.php","line":89,"function":"linkToOCSRouteAbsolute","class":"OC\\URLGenerator","type":"->","args":["provisioning_api.AppsController.disable",{"app":"nextcloud_announcements"}]},{"file":"\/var\/www\/nextcloud\/lib\/private\/Notification\/Manager.php","line":226,"function":"prepare","class":"OCA\\NextcloudAnnouncements\\Notification\\Notifier","type":"->","args":[{"__class__":"OC\\Notification\\Notification"},"de_DE"]},{"file":"\/var\/www\/nextcloud\/apps\/notifications\/lib\/Controller\/EndpointController.php","line":92,"function":"prepare","class":"OC\\Notification\\Manager","type":"->","args":[{"__class__":"OC\\Notification\\Notification"},"de_DE"]},{"file":"\/var\/www\/nextcloud\/lib\/private\/AppFramework\/Http\/Dispatcher.php","line":166,"function":"listNotifications","class":"OCA\\Notifications\\Controller\\EndpointController","type":"->","args":["v2"]},{"file":"\/var\/www\/nextcloud\/lib\/private\/AppFramework\/Http\/Dispatcher.php","line":99,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Notifications\\Controller\\EndpointController"},"listNotifications"]},{"file":"\/var\/www\/nextcloud\/lib\/private\/AppFramework\/App.php","line":126,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Notifications\\Controller\\EndpointController"},"listNotifications"]},{"file":"\/var\/www\/nextcloud\/lib\/private\/AppFramework\/Routing\/RouteActionHandler.php","line":47,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\Notifications\\Controller\\EndpointController","listNotifications",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"apiVersion":"v2","_route":"ocs.notifications.Endpoint.listNotifications"}]},{"function":"__invoke","class":"OC\\AppFramework\\Routing\\RouteActionHandler","type":"->","args":[{"apiVersion":"v2","_route":"ocs.notifications.Endpoint.listNotifications"}]},{"file":"\/var\/www\/nextcloud\/lib\/private\/Route\/Router.php","line":297,"function":"call_user_func","args":[{"__class__":"OC\\AppFramework\\Routing\\RouteActionHandler"},{"apiVersion":"v2","_route":"ocs.notifications.Endpoint.listNotifications"}]},{"file":"\/var\/www\/nextcloud\/ocs\/v1.php","line":82,"function":"match","class":"OC\\Route\\Router","type":"->","args":["\/ocsapp\/apps\/notifications\/api\/v2\/notifications"]},{"file":"\/var\/www\/nextcloud\/ocs\/v2.php","line":24,"args":["\/var\/www\/nextcloud\/ocs\/v1.php"],"function":"require_once"}],"File":"\/var\/www\/nextcloud\/3rdparty\/symfony\/routing\/Generator\/UrlGenerator.php","Line":130,"CustomMessage":"--"},"userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwG38AAQEAAAPJzy4AAAEA","level":2,"time":"2019-11-10T11:10:20+00:00","remoteAddr":"79.199.41.191","user":"andi","app":"no app in context","method":"GET","url":"\/ocs\/v2.php\/cloud\/activity?start=0&count=100&format=json","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwMH8AAQEAAAPJzzAAAAMB","level":2,"time":"2019-11-10T11:10:40+00:00","remoteAddr":"79.199.41.191","user":"andi","app":"no app in context","method":"PROPFIND","url":"\/remote.php\/dav\/files\/andi\/","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}
{"reqId":"XcfwMH8AAQEAAAPJzzEAAAIA","level":2,"time":"2019-11-10T11:10:40+00:00","remoteAddr":"79.199.41.191","user":"ncp","app":"no app in context","method":"PROPFIND","url":"\/remote.php\/dav\/files\/ncp\/","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.6.0stable-Win64 (build 20190927) (Nextcloud)","version":"16.0.5.1"}

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

config.php ``` <?php $CONFIG = array ( 'passwordsalt' => 'PASSWORD', 'secret' => 'PASSWORD', 'trusted_domains' => array ( 0 => 'localhost', 5 => 'nextcloudpi.local', 7 => 'nextcloudpi', 8 => 'nextcloudpi.lan', 1 => 'IP-ADDRESS', 3 => 'WEBADDRESS', 4 => 'WEBADDRESS', 11 => 'IP-ADDRESS', ), 'datadirectory' => '/media/USBdrive1/ncdata', 'dbtype' => 'mysql', 'version' => '16.0.5.1', 'overwrite.cli.url' => 'WEBADDRESS', 'dbname' => 'nextcloud', 'dbhost' => 'localhost', 'dbport' => '', 'dbtableprefix' => 'oc_', 'mysql.utf8mb4' => true, 'dbuser' => 'ncadmin', 'dbpassword' => 'PASSWORD', 'installed' => true, 'instanceid' => 'ockubejeb23o', 'memcache.local' => '\\OC\\Memcache\\Redis', 'memcache.locking' => '\\OC\\Memcache\\Redis', 'redis' => array ( 'host' => '/var/run/redis/redis.sock', 'port' => 0, 'timeout' => 0.0, 'password' => 'PASSWORD', ), 'mail_smtpmode' => 'sendmail', 'mail_smtpauthtype' => 'LOGIN', 'mail_from_address' => 'admin', 'mail_domain' => 'ownyourbits.com', 'overwriteprotocol' => 'https', 'loglevel' => '2', 'log_type' => 'file', 'maintenance' => false, 'logfile' => '/media/USBdrive1/ncdata/nextcloud.log', 'htaccess.RewriteBase' => '/', 'skeletondirectory' => '', 'jpeg_quality' => '60', 'preview_max_x' => '2048', 'preview_max_y' => '2048', 'theme' => '', ); ```

in webgui of ncp there should be an option for changing permissions (or updating or resetting or such). have you tried these?

This is the output of fix-permissions in the Web-UI:

[ nc-fix-permissions ]
Cannot load Zend OPcache - it was already loaded
{"reqId":"LmWFCOUsfHbooTIOqSpX","level":2,"time":"2019-11-10T13:28:06+00:00","remoteAddr":"","user":"--","app":"no app in context","method":"","url":"--","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"--","version":"16.0.5.1"}
{"reqId":"LmWFCOUsfHbooTIOqSpX","level":3,"time":"2019-11-10T13:28:08+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/data_dir_writability_test_5dc8106885cc1.tmp): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/legacy\/util.php#796","userAgent":"--","version":"16.0.5.1"}
{"reqId":"LmWFCOUsfHbooTIOqSpX","level":3,"time":"2019-11-10T13:28:08+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/nextcloud.log): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/Log\/File.php#139","userAgent":"--","version":"16.0.5.1"}

The SD card is ok?
Can you write anything to it?
# sudo touch test

Edit: BTW - the error message seams to be a little bit misleading and is perhaps good to report on github too. If you look closely to your logs, then it is not so much the USB-drive, that is not writable but the SD-card. No temp files, no cache files can be written.

Best, Bernd

When executing ‘touch test’ I get the following output:

touch: cannot touch 'test': Read-only file system

Thank you. I will report it on github, too. But I still hope, someone here knows a solution for my problem.

Yes - well even if it sounds harsh - I think you have to buy a new SD card… (you can search around the internet. A so called hardware defect is not so rare on SD cards, USB flash drives …) The read only mode is some kind of security level so that you can make a backup for a longer time.

Make a backup of your SD-card etc.

Depending on the projects you run on this raspi / users connected to nextcloud etc … fresh install on new SD card and copying files?

Ok, I didn’t expect this. I think, I’ll wait for some other responses, also on GitHub before executing your advice. The thing is that I can’t even make a current backup. When trying to execute ‘nc-backup’ I get the following output:

Running nc-backup
Cannot load Zend OPcache - it was already loaded
{"reqId":"XOFwrPas8zkVXsAkfVbt","level":2,"time":"2019-11-10T16:28:26+00:00","remoteAddr":"","user":"--","app":"no app in context","method":"","url":"--","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"--","version":"16.0.5.1"}
{"reqId":"XOFwrPas8zkVXsAkfVbt","level":3,"time":"2019-11-10T16:28:28+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/data_dir_writability_test_5dc83aacc13f9.tmp): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/legacy\/util.php#796","userAgent":"--","version":"16.0.5.1"}
{"reqId":"XOFwrPas8zkVXsAkfVbt","level":3,"time":"2019-11-10T16:28:28+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/nextcloud.log): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/Log\/File.php#139","userAgent":"--","version":"16.0.5.1"}
Error reading data directory. Is NextCloud running and configured?
Done. Press any key...

Also, for nc-snapshot:

Running nc-snapshot
Cannot load Zend OPcache - it was already loaded
{"reqId":"TzbwdKLBnp4vBpnq9QXL","level":2,"time":"2019-11-10T16:30:08+00:00","remoteAddr":"","user":"--","app":"no app in context","method":"","url":"--","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"--","version":"16.0.5.1"}
{"reqId":"TzbwdKLBnp4vBpnq9QXL","level":3,"time":"2019-11-10T16:30:10+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/data_dir_writability_test_5dc83b1258b41.tmp): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/legacy\/util.php#796","userAgent":"--","version":"16.0.5.1"}
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/16/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}{"reqId":"TzbwdKLBnp4vBpnq9QXL","level":3,"time":"2019-11-10T16:30:10+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/nextcloud.log): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/Log\/File.php#139","userAgent":"--","version":"16.0.5.1"}
Cannot load Zend OPcache - it was already loaded
{"reqId":"KNRI9sb19luOV7qVPzdU","level":2,"time":"2019-11-10T16:30:12+00:00","remoteAddr":"","user":"--","app":"no app in context","method":"","url":"--","message":"Temporary directory \/var\/www\/nextcloud\/data\/tmp is not present or writable","userAgent":"--","version":"16.0.5.1"}
{"reqId":"KNRI9sb19luOV7qVPzdU","level":3,"time":"2019-11-10T16:30:13+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/data_dir_writability_test_5dc83b159f9eb.tmp): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/legacy\/util.php#796","userAgent":"--","version":"16.0.5.1"}
{"reqId":"KNRI9sb19luOV7qVPzdU","level":3,"time":"2019-11-10T16:30:13+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(\/media\/USBdrive1\/ncdata\/nextcloud.log): failed to open stream: Read-only file system at \/var\/www\/nextcloud\/lib\/private\/Log\/File.php#139","userAgent":"--","version":"16.0.5.1"}
Error reading data directory. Is NextCloud running?
Done. Press any key...

I guess I have to deal with the fact that I may get a little bit of data loss.

@TheFrisbee – Welcome!

@lebernd – Not so fast … if I may.

IMHO there may be still some SD-cards around with a tiny switch as an valid option to enable or disable some hardware protection against false writes. Furthermore, there may some other hardware and/or firmware option to ensure some write protect for a SD-card be around on an embedded CPU board.

Please check if your SD-card owns such hardware switch first, I presume.

Good luck.
:four_leaf_clover:

No - I don’t think that will be too much of a problem! But you will have hassles with setting everything up and running. The files are on your USB drive? So that’s fine.

Sure you may and I’m glad you did! And you are right one can check better than I did.
It just seamed so very likely from my perspective. SD cards are not really the ideal storage for database applications?!

1 Like

Thank you both for your replies.
@TP75 Unfortunately, my SD Card doesn’t have such a hardware switch.
@lebernd Yes, the data is on the USB Stick and not on the SD Card.

1 Like

Just check the USB-stick for such hardware switch and/or possible firmware option in a similar way.

IMHO you should use a more conservative approach and may avoid some troubles if you stick to on-board hardware options over attached memory as any plugged hardware interface brings both some connection troubles (bare physics of electrical material) and some extra risk in adding complexity. Last not least some thingies which are plugged-in may be get plugged-out just by accident.

You never heard of such occasions? I did.
:innocent:

You can try to run some tar-commands to backup needed directories.
Like at least:

mkdir /media/USBdrive1/backup 
tar -cvf /media/USBdrive1/backup/back-etc.tar /etc
tar -cvf /media/USBdrive1/backup/back-www.tar /var/www
tar -cvf /media/USBdrive1/backup/back-lib.tar /var/lib

What is the output of sudo cat /etc/fstab ?

Next: What other computer has a card-reader? What operating system is running there? LIN-macos-WIN? Make an image of the SD card before you try to edit files there. Other recovery programs installed there? Tests for SD hardware defects?
Some looking around :eyes: took me here:

Best, Bernd

Was the sd card damaged?
I got this error:

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/16/go.php?to=admin-dir_permissions.

But the side does not help. Is my sd card faulty? I can still connect via ssh to the raspi.
Access via admin web gui is still possible.
NC-snapshot gives me:
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}{“reqId”:“xyz”,“level”:3,“time”:“2019-12-13T21:28:39+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“fopen(/media/NCP/nc-data/nextcloud.log): failed to open stream: Read-only file system at /var/www/nextcloud/lib/private/Log/File.php#139”,“userAgent”:"–",“version”:“16.0.5.1”}
{“reqId”:“xyz”,“level”:2,“time”:“2019-12-13T21:28:40+00:00”,“remoteAddr”:"",“user”:"–",“app”:“no app in context”,“method”:"",“url”:"–",“message”:“Temporary directory /media/NCP/nc-data/tmp is not present or writable”,“userAgent”:"–",“version”:“16.0.5.1”}
{“reqId”:“OSVSJ7wLRK5UsVH9jSMQ”,“level”:3,“time”:“2019-12-13T21:28:43+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“fopen(/media/NCP/nc-data/data_dir_writability_test_5df4028b09063.tmp): failed to open stream: Read-only file system at /var/www/nextcloud/lib/private/legacy/util.php#796”,“userAgent”:"–",“version”:“16.0.5.1”}
{“reqId”:“xyz”,“level”:3,“time”:“2019-12-13T21:28:43+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“fopen(/media/NCP/nc-data/nextcloud.log): failed to open stream: Read-only file system at /var/www/nextcloud/lib/private/Log/File.php#139”,“userAgent”:"–",“version”:“16.0.5.1”}
Error reading data directory. Is NextCloud running?

How do i fix permissions or do i just need a new sd card?

Try nc-fix-permissions
from ncp web or terminal

sudo ncp-config

find TOOLS and run nc-fix-permissions

That is not working.
Running nc-fix-permissions
{“reqId”:“xyz”,“level”:2,“time”:“2019-12-21T10:41:59+00:00”,“remoteAddr”:"",“user”:"–",“app”:“no app in context”,“method”:"",“url”:"–",“message”:“Temporary directory /media/NCP/nc-data/tmp is not present or writable”,“userAgent”:"–",“version”:“16.0.5.1”}
{“reqId”:“xyz”,“level”:3,“time”:“2019-12-21T10:42:01+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“fopen(/media/NCP/nc-data/data_dir_writability_test_5dfdf6f94dc37.tmp): failed to open stream: Read-only file system at /var/www/nextcloud/lib/private/legacy/util.php#796”,“userAgent”:"–",“version”:“16.0.5.1”}
{“reqId”:“xyz”,“level”:3,“time”:“2019-12-21T10:42:01+00:00”,“remoteAddr”:"",“user”:"–",“app”:“PHP”,“method”:"",“url”:"–",“message”:“fopen(/media/NCP/nc-data/nextcloud.log): failed to open stream: Read-only file system at /var/www/nextcloud/lib/private/Log/File.php#139”,“userAgent”:"–",“version”:“16.0.5.1”}
data directory not found
Done. Press any key…

Check if PATH to data directory is correctly set in both
/etc/php/7.3/fpm/php.ini
and
/path/to/nextcloud/config/config.php

/etc/php/7.3/fpm/php.ini -> where do i have to look? It is a very large file.

/path/to/nextcloud/config/config.php -> ‘datadirectory’ => ‘/media/NCP/nc-data’,

sys_temp_dir

both are ok. I noticed that I have no write permission on the usb drive. Not even as root. How is that possible? Can it be connected with encryption?