N24 fresh install - can't enable Collabora Online - Built-in CODE Server

Nextcloud version 24.0.1
Operating system and version Ubuntu 22.04
nginx version 1.18.0
PHP version 8.1

The issue you are facing:
Enabling Collabora Online - Built-in CODE Server causes “Internal Server Error”. Nextcloud won’t open.
I have to use sudo -u www-data php -d memory_limit=512M ./occ app:remove richdocumentscode for nextcloud to work again.

Is this the first time you’ve seen this error? Yes

Steps to replicate it:

  1. Install NextCloud on Ubuntu 22.04 (Nginx + PostgreSQL + PHP8.1)
    https://www.linuxbabe.com/ubuntu/install-nextcloud-ubuntu-22-04-nginx-postgresql
  2. Enable Collabora Online - Built-in CODE Server
  3. Open nextcloud instance

The output of your Nextcloud log in Admin > Logging:

OCP\AppFramework\QueryException: Could not resolve externalMountProvider! Class "externalMountProvider" does not exist
OCP\AppFramework\QueryException: Could not resolve OCA\Files_Versions\Versions\IVersionManager! Class can not be instantiated
OCP\AppFramework\QueryException: Could not resolve trashManager! Class "trashManager" does not exist
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: remaining connection slots are reserved for non-replication superuser connections

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

<?php
$CONFIG = array (
  'instanceid' => '*****',
  'passwordsalt' => '*****',
  'secret' => '*****',
  'trusted_domains' => 
  array (
    0 => 'my.domain.com',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'pgsql',
  'version' => '24.0.1.1',
  'overwrite.cli.url' => 'http://my.domain.com',
  'dbname' => '*****',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => '*****',
  'dbpassword' => '*****',
  'installed' => true,
  'theme' => '',
  'loglevel' => 2,
  'maintenance' => false,
'trusted_proxies' =>
  array (
    0 => 'my.reverseproxy.address',
  ),
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => array(
     'host' => 'localhost',
     'port' => 6379,
     ),


);

The output of your Apache/nginx/system log in /var/log/nextcloud.access:

"GET /apps/richdocumentscode/proxy.php?req=/hosting/capabilities HTTP/1.1" 302 5 "-" "Nextcloud Server Crawler"
"GET /apps/richdocumentscode/proxy.php?req=/hosting/capabilities HTTP/1.1" 500 3048 "-" "Nextcloud Server Crawler"

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.

[error] 1961#1961: *27180 recv() failed (104: Unknown error) while reading response header from upstream, client: my.reverseproxy.address, server: my.domain.com request: "GET /richdocumentscode/proxy.php?req=/hosting/capabilities HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.1-fpm.sock:", host: "my.domain.com"