Error 503/Configuration was not read or initialized correctly after sudo chown -R www-data:www-data /var/snap/nextcloud

[/details]

Nextcloud version (eg, 20.0.5): 27
Operating system and version (eg, Ubuntu 20.04): Ubuntu server 22.04
Apache or nginx version (eg, Apache 2.4.25): 2.4
PHP version (eg, 7.4): 8.1

The issue you are facing:
Hey, i tryed to install Nextcloud on my ubuntu server but when i after i changed the autoconfig to /media/data nextcloud needed the permissions for the folder again so i ran sudo chown -R www-data:www-data /var/snap/nextcloud. After that i got the error [Configuration was not read or initialized correctly]. After a reboot i only get Error 503. The error logs are empty.

Is this the first time you’ve seen this error? : Y

The output of your Nextcloud log in Admin > Logging:

nothing

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

<?php
$CONFIG = array (
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/snap/nextcloud/current/htdocs/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/snap/nextcloud/current/nextcloud/extra-apps',
      'url' => '/extra-apps',
      'writable' => true,
    ),
  ),
  'supportedDatabases' =>
  array (
    0 => 'mysql',
  ),
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => '/tmp/sockets/redis.sock',
    'port' => 0,
  ),
  'log_type' => 'file',
  'logfile' => '/var/snap/nextcloud/current/logs/nextcloud.log',
  'logfilemode' => 416,
  'instanceid' => 'oc9xohebry53',
  'passwordsalt' => 'bg7A2R6ceNLDiNNW6Wt+YrJaEAyrOn',
  'secret' => '+4vgJL1FYNxzXtDM26yN1itLPtev79Xs/yzF6GRD1FT07zC4',
  'trusted_domains' =>
  array (
    0 => '192.168.0.104',
  ),
  'datadirectory' => '/media/data',
  'dbtype' => 'mysql',
  'version' => '27.1.3.2',
  'overwrite.cli.url' => 'http://192.168.0.104',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:/tmp/sockets/mysql.sock',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'CAyHIBCy9D3JLUr_x4xS1hub-haaiPjkDL2N8cDfwkLX5SrCLOvHEENRFZ1Yw7Ze',
  'installed' => true,
);

the passwords in the config are not the current ones, i tried reinstalling nextcloud but got the same results; this is the old config, but i didnt change anything in both configs, only in the autoconfig

Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

cant log in