Your data directory is invalid

I am running nextcloud version 20 on a web hosting and encountered the same problem. The above solution workes only until an app is updated or an update is inserted for an app. Then the config file is overwritten (makes sense because apps sometimes create parameters here).

This solution works permanently:

  1. Create a new file in config/ folder: datadirectory.config.php
  2. Insert into file:
<?php

if (\OC::$CLI) {
	$CONFIG['datadirectory'] = '/path/cli';
} else {
	$CONFIG['datadirectory'] = '/path/web';
}