Data directory is invalid. Please check that the data directory contains a file “.ocdata” in its root

I tried everything to fix this, but it’s not working. The .ocdata file exists but it shows this error since I changed my data path in the config.

Changing the data directory in the config is not enough. Did you read this?

Thanks for help. I reinstalled Nextcloud and I get the same error again.

I would do this: copy all the contents of the data directory to a save place. Reinstall with an empty data directory. Check that nextcloud works. Copy back your data directory content from your backup. Resync the content by command:
sudo -u www-data php occ files:scan --all
The user www-data works for Debian/Ubuntu systems. For other systems, check the user id of the web server.

I already deleted the Data directory completely and reinstalled nextcloud with an new Data folder. The Cloud works fine but it shows that error again.

Did you also recreate the database?

So I have to delete the MySQL Database too?

When you create the cloud from scratch, I guess this would be better. So there are no artifacts of the old installation.

@leginhee Have you tried to change the datadirectory Property in config.php dynamically depending on which php interface is running? See my answer in a similar thread. This works for UI and for occ commands. I couldn’t figure it out though, how to get rid of the message of the problem&security scanner.

Update: changing the config.php files is not supported, but in the thread mentioned above I found and linked a solution that works also over app updates etc. :slight_smile: