Your data directory is invalid Ensure

I’m getting the following error when trying to access Nextcloud:

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

My config.php:

<?php
$CONFIG = array (
  'instanceid' => 'XX',
  'passwordsalt' => 'XXX',
  'secret' => 'OA+XXX',
  'trusted_domains' => 'MY IP ADDRESS',
  array (
    0 => 'example.com',
  ),
  'datadirectory' => '/var/www/ncdata',
  'dbtype' => 'mysql',
  'version' => '19.0.3.1',
  'overwrite.cli.url' => 'https://example.com/',
  'htaccess.RewriteBase' => 'var/www/html',
  'installed' => true,
  'maintenance' => false,
  'app_install_overwrite' => 
  array (
    0 => 'recommendation_assistant',
    1 => 'caniupdate',
    2 => 'admin_notifications',
    3 => 'end_to_end_encryption',
  ),
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\APCu',
  'redis' => 
  array (
    'host' => 'localhost',
    'port' => 6379,
    'timeout' => 0.0,
    'password' => '',
  ),
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'XXX',
  'dbpassword' => 'XXX',
  'updater.secret' => 'XXX',
  'theme' => '',
  'loglevel' => 2,
  'mysql.utf8mb4' => true,
  'updater.release.channel' => 'stable',
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' => 
  array (
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
    0 => 'admin',
  ),
);

OS is CentOS

I have already tried to change data folder ownership to www-data