Nextcloud data location change

Nextcloud version (17.0.1):
Operating system and version (Raspberry pi 4 Buster):
Apache or nginx version (Apache 2.4.38):
PHP version (7.3):

The issue you are facing:

I managed to get nextcloud working on my raspberry pi so I then tried to change the data directory to an external hard drive, by executing the code below and then restarting apache. But when I reached the website I was met with this:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

I then checked the apache log and saw that it was written permission failure as such I gave the permissions needed to the data directory, however this did not fix the problem.

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

Steps to replicate it:

  1. sudo mv /var/nextcloud/data /media/pi/data
  2. sudo ln -s /media/pi/data /var/nextcloud/data

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

<?php
$CONFIG = array (
  'instanceid' => 'occy4b12ybks',
  'passwordsalt' => 'xxxxxxxx',
  'secret' => 'xxxxxxx',
  'trusted_domains' => 
  array (
    0 => 'xxxxxx',
  ),
  'datadirectory' => '/var/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '17.0.1.1',
  'overwrite.cli.url' => 'http://xxxxxxx/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'xxxxxx',
  'dbpassword' => 'xxxxxxx',
  'installed' => true,
);


The output of your Apache/nginx/system log in /var/log/____:

[Sun Mar 22 13:04:40.718571 2020] [php7:warn] [pid 2258] [client xxxx] PHP Warning:  fileperms(): stat failed for /var/nextcloud/data/nextcloud.log in /var/www/html/nextcloud/lib/private/Log/File.php on line 85
[Sun Mar 22 13:04:40.718793 2020] [php7:notice] [pid 2258] [client xxxx] {"reqId":"xxxx","level":3,"time":"2020-03-22T13:04:40+00:00","remoteAddr":"xxxx","user":"admin","app":"PHP","method":"GET","url":"\\/nextcloud\\/index.php","message":"file_get_contents(\\/var\\/nextcloud\\/data\\/appdata_occy4b12ybks\\/js\\/core\\/merged-template-prepend.js.deps): failed to open stream: Permission denied at \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/Files\\/Storage\\/Local.php#217","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/80.0.3987.149 Safari\\/537.36","version":"17.0.1.1"}
[Sun Mar 22 13:04:40.719726 2020] [php7:warn] [pid 2258] [client xxxx] PHP Warning:  fileperms(): stat failed for /var/nextcloud/data/nextcloud.log in /var/www/html/nextcloud/lib/private/Log/File.php on line 85
[Sun Mar 22 13:04:40.719779 2020] [php7:notice] [pid 2258] [client xxxx] {"reqId":"xxxx","level":3,"time":"2020-03-22T13:04:40+00:00","remoteAddr":"xxxx","user":"admin","app":"PHP","method":"GET","url":"\\/nextcloud\\/index.php","message":"stat(): stat failed for \\/var\\/nextcloud\\/data\\/appdata_occy4b12ybks\\/js\\/core\\/merged-template-prepend.js.deps at \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/Files\\/Storage\\/Local.php#143","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/80.0.3987.149 Safari\\/537.36","version":"17.0.1.1"}
stat: cannot stat '/var/nextcloud/data/appdata_occy4b12ybks/js/core/merged-template-prepend.js.deps': Permission denied
[Sun Mar 22 13:04:40.733321 2020] [php7:warn] [pid 2258] [client xxxx] PHP Warning:  fileperms(): stat failed for /var/nextcloud/data/nextcloud.log in /var/www/html/nextcloud/lib/private/Log/File.php on line 85
[Sun Mar 22 13:04:40.733389 2020] [php7:notice] [pid 2258] [client xxxx] {"reqId":"xxxx","level":3,"time":"2020-03-22T13:04:40+00:00","remoteAddr":"xxxx","user":"admin","app":"PHP","method":"GET","url":"\\/nextcloud\\/index.php","message":"filesize(): stat failed for \\/var\\/nextcloud\\/data\\/appdata_occy4b12ybks\\/js\\/core\\/merged-template-prepend.js.deps at \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/LargeFileHelper.php#171","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/80.0.3987.149 Safari\\/537.36","version":"17.0.1.1"}
[Sun Mar 22 13:04:40.738003 2020] [php7:warn] [pid 2258] [client xxxx] PHP Warning:  fileperms(): stat failed for /var/nextcloud/data/nextcloud.log in /var/www/html/nextcloud/lib/private/Log/File.php on line 85
[Sun Mar 22 13:04:40.738077 2020] [php7:notice] [pid 2258] [client xxxx] {"reqId":"xxxx","level":3,"time":"2020-03-22T13:04:40+00:00","remoteAddr":"xxxx","user":"admin","app":"PHP","method":"GET","url":"\\/nextcloud\\/index.php","message":"file_put_contents(\\/var\\/nextcloud\\/data\\/appdata_occy4b12ybks\\/js\\/core\\/merged-template-prepend.js): failed to open stream: No such file or directory at \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/Files\\/Storage\\/Local.php#221","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/80.0.3987.149 Safari\\/537.36","version":"17.0.1.1"}
[Sun Mar 22 13:04:40.739530 2020] [php7:warn] [pid 2258] [client xxxx] PHP Warning:  fileperms(): stat failed for /var/nextcloud/data/nextcloud.log in /var/www/html/nextcloud/lib/private/Log/File.php on line 85
[Sun Mar 22 13:04:40.739589 2020] [php7:notice] [pid 2258] [client xxxx] {"reqId":"xxxx","level":3,"time":"2020-03-22T13:04:40+00:00","remoteAddr":"xxxx","user":"admin","app":"PHP","method":"GET","url":"\\/nextcloud\\/index.php","message":"fileperms(): stat failed for \\/var\\/nextcloud\\/data\\/nextcloud.log at \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/Log\\/File.php#85","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/80.0.3987.149 Safari\\/537.36","version":"17.0.1.1"}
[Sun Mar 22 13:04:40.757844 2020] [php7:warn] [pid 2258] [client xxxx] PHP Warning:  fileperms(): stat failed for /var/nextcloud/data/nextcloud.log in /var/www/html/nextcloud/lib/private/Log/File.php on line 85
[Sun Mar 22 13:04:40.757912 2020] [php7:notice] [pid 2258] [client xxxx] {"reqId":"xxxx","level":3,"time":"2020-03-22T13:04:40+00:00","remoteAddr":"xxxx","user":"admin","app":"PHP","method":"GET","url":"\\/nextcloud\\/index.php","message":"filesize(): stat failed for \\/var\\/nextcloud\\/data\\/appdata_occy4b12ybks\\/js\\/core\\/merged-template-prepend.js.deps at \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/LargeFileHelper.php#171","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/80.0.3987.149 Safari\\/537.36","version":"17.0.1.1"}
[Sun Mar 22 13:04:40.762080 2020] [php7:warn] [pid 2258] [client xxxx] PHP Warning:  fileperms(): stat failed for /var/nextcloud/data/nextcloud.log in /var/www/html/nextcloud/lib/private/Log/File.php on line 85
[Sun Mar 22 13:04:40.762150 2020] [php7:notice] [pid 2258] [client xxxx] {"reqId":"xxxx","level":3,"time":"2020-03-22T13:04:40+00:00","remoteAddr":"xxxx","user":"admin","app":"PHP","method":"GET","url":"\\/nextcloud\\/index.php","message":"file_put_contents(\\/var\\/nextcloud\\/data\\/appdata_occy4b12ybks\\/js\\/core\\/merged-template-prepend.js): failed to open stream: No such file or directory at \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/Files\\/Storage\\/Local.php#221","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/80.0.3987.149 Safari\\/537.36","version":"17.0.1.1"}
[Sun Mar 22 13:04:40.763403 2020] [php7:warn] [pid 2258] [client xxxx] PHP Warning:  fileperms(): stat failed for /var/nextcloud/data/nextcloud.log in /var/www/html/nextcloud/lib/private/Log/File.php on line 85
[Sun Mar 22 13:04:40.763457 2020] [php7:notice] [pid 2258] [client xxxx] {"reqId":"xxxx","level":3,"time":"2020-03-22T13:04:40+00:00","remoteAddr":"xxxx","user":"admin","app":"PHP","method":"GET","url":"\\/nextcloud\\/index.php","message":"fileperms(): stat failed for \\/var\\/nextcloud\\/data\\/nextcloud.log at \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/Log\\/File.php#85","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/80.0.3987.149 Safari\\/537.36","version":"17.0.1.1"}
[Sun Mar 22 13:04:40.764522 2020] [php7:warn] [pid 2258] [client xxxx] PHP Warning:  fileperms(): stat failed for /var/nextcloud/data/nextcloud.log in /var/www/html/nextcloud/lib/private/Log/File.php on line 85
[Sun Mar 22 13:04:40.764569 2020] [php7:notice] [pid 2258] [client xxxx] {"reqId":"xxxx","level":3,"time":"2020-03-22T13:04:40+00:00","remoteAddr":"xxxx","user":"admin","app":"PHP","method":"GET","url":"\\/nextcloud\\/index.php","message":"fileperms(): stat failed for \\/var\\/nextcloud\\/data\\/nextcloud.log at \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/Log\\/File.php#85","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/80.0.3987.149 Safari\\/537.36","version":"17.0.1.1"}
[Sun Mar 22 13:04:40.765232 2020] [php7:warn] [pid 2258] [client xxxx] PHP Warning:  fileperms(): stat failed for /var/nextcloud/data/nextcloud.log in /var/www/html/nextcloud/lib/private/Log/File.php on line 85
[Sun Mar 22 13:04:40.765291 2020] [php7:notice] [pid 2258] [client xxxx] {"reqId":"xxxx","level":3,"time":"2020-03-22T13:04:40+00:00","remoteAddr":"xxxx","user":"admin","app":"PHP","method":"GET","url":"\\/nextcloud\\/index.php","message":"fileperms(): stat failed for \\/var\\/nextcloud\\/data\\/nextcloud.log at \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/Log\\/File.php#85","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/80.0.3987.149 Safari\\/537.36","version":"17.0.1.1"}

Kind regards

I think you pust change in config.php the path to “/media/pi/data” and not use a symbolic link.

Also check the permissions for /media/pi/data (www-data:www-data).

I think you must rescan:

https://docs.nextcloud.com/server/18/admin_manual/configuration_server/occ_command.html

option: files:scan

I have changed the config path.

Permissions for /media/pi/data:
drwxrwxrwx 5 www-data www-data 4096 Mar 22 15:34 data

I tried running the file scan, this is what it returned:

Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

Cannot create "data" directory
This 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/html/nextcloud/lib/private/Console/Application.php:166
Stack trace:
#0 /var/www/html/nextcloud/console.php(96): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /var/www/html/nextcloud/occ(11): require_once('/var/www/html/n...')

I have tried adding the .ocdata file but I just end up receiving the same message.

Found the problem did a fresh reinstall and found that nextcloud could not read the parent directories. (thanks to tflidd for that Moving "data" folder to a new location (external HDD))