I have been struggling with this issue all week and finally came across this very useful thread. Thanks to all contributors. However, after going through the various items listed above in robertb’s posting of Sep '16 I still had the mentioned error :
Data directory (/etc/nextclouddata/nextcloud/data/) is invalid. Please check that the data directory contains a file “.ocdata” in its root.
I had learnt in other attempts that the nextcloud.conf has also to be modified by adding the new data directory path as follows (using robertb’s data directory as an example) :
php_admin_value open_basedir “/srv/http/:/dev/urandom:/tmp/:/usr/share/pear/:/usr/share/webapps/nextcloud/:/etc/webapps/:/etc/nextclouddata/nextcloud/data/”
So I tried adding my path and all is working again with a new directory path.
Hope this comment might help those using Nextcloud 11.
Note : I am running on Archlinux so the apache user is “http” and not “www-data”