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

Nextcloud version (eg, 18.0.2): Nextcloud 20.0.2
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04.1 LTS
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.41 (Ubuntu)
PHP version (eg, 7.1): PHP 7.4.13

The issue you are facing:

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

After installing nextcloud, i get following error on page

https://mydomain/settings/admin/overview

It was not possible to execute the cron job via CLI. The following technical errors have appeared:
Your data directory is invalid Ensure there is a file called “.ocdata” in the root of the data directory.

I verified .ocdata is present in the ServerOk

www-data@ip-172-31-31-32:~/nextcloud$ ls -la /var/www/nextcloud-data
total 48
drwxrwx---  5 www-data www-data  4096 Nov 30 20:44 .
drwxr-xr-x  5 www-data www-data  4096 Nov 30 20:12 ..
-rw-r--r--  1 www-data www-data   542 Nov 30 09:29 .htaccess
-rwxrwxrwx  1 www-data www-data     0 Nov 30 09:29 .ocdata
drwxr-xr-x  4 www-data www-data  4096 Nov 30 09:57 admin
drwxr-xr-x 10 www-data www-data  4096 Nov 30 09:35 appdata_oct8greq5czw
-rw-r--r--  1 www-data www-data     0 Nov 30 20:14 flow.log
-rw-r--r--  1 www-data www-data     0 Nov 30 09:29 index.html
drwx------  2 www-data www-data 16384 Nov 30 09:30 lost+found
-rw-r-----  1 www-data www-data  8395 Nov 30 20:03 nextcloud.log
www-data@ip-172-31-31-32:~/nextcloud$ cat config/config.php | grep datadir
  'datadirectory' => '/var/www/nextcloud-data',
www-data@ip-172-31-31-32:~/nextcloud$ php /var/www/nextcloud/occ files:scan --all
Starting scan for user 1 out of 1 (admin)
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 6       | 19    | 00:00:00     |
+---------+-------+--------------+
www-data@ip-172-31-31-32:~/nextcloud$ 

The output of your Nextcloud log in Admin > Logging:

No errors reported

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

<?php
$CONFIG = array (
  'instanceid' => 'ocxxxxxxxxczw',
  'passwordsalt' => 'gmxxxxxxxxvBV',
  'secret' => 'icxxxxxxxx/',
  'trusted_domains' => 
  array (
    0 => 'xxxxxxxxcom',
  ),
  'datadirectory' => '/var/www/nextcloud-data',
  'dbtype' => 'mysql',
  'version' => '20.0.2.2',
  'overwrite.cli.url' => 'https://xxxxxxxxcom',
  'dbname' => 'xxxxxxxx',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'xxxxxxxx',
  'dbpassword' => 'xxxxxxxx',
  'installed' => true,
  'htaccess.RewriteBase' => '/',


'preview_libreoffice_path' => '/usr/bin/libreoffice',
'enable_previews' => true,
'enabledPreviewProviders' =>
 array (
    0 => 'OC\\Preview\\TXT',
    1 => 'OC\\Preview\\MarkDown',
    2 => 'OC\\Preview\\OpenDocument',
    3 => 'OC\\Preview\\PDF',
    4 => 'OC\\Preview\\MSOffice2003',
    5 => 'OC\\Preview\\MSOfficeDoc',
    6 => 'OC\\Preview\\PDF',
    7 => 'OC\\Preview\\Image',
    8 => 'OC\\Preview\\Photoshop',
    9 => 'OC\\Preview\\TIFF',
   10 => 'OC\\Preview\\SVG',
   11 => 'OC\\Preview\\Font',
   12 => 'OC\\Preview\\MP3',
   13 => 'OC\\Preview\\Movie',
   14 => 'OC\\Preview\\MKV',
   15 => 'OC\\Preview\\MP4',
   16 => 'OC\\Preview\\AVI',
 ),

);

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

No errors listed in apache error log

Is the cron running as your webserver user www-data?
For a similar problem, I suggested to add something in the logs to know where it is looking and having troubles:

Thanks for the reply. Cronjob was not set. Adding cron job fixed the error.