Nextcloud error 500 after every reboot

Nextcloud version (eg, 20.0.5): ‘23’
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): nginx 1.21.5
PHP version (eg, 7.4): 8.0.14

The issue you are facing:
Nextcloud inaccessible with internal server error 500 every time the host is rebooted for any reason. It started some time when the containers were all in earlier versions and has persisted until now. Most recently, I rebooted while expanding LVM. It occasionally seems to start working again after a reboot or docker-compose up for no reason I can tell. I haven’t been able to get much information from logs. Apologies and thank you in advance, I’m very new to docker, proxies, and NC. I’m not even sure the logs I’m providing are right…

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

Steps to replicate it:

  1. Reboot Server

Nextcloud log:

sudo docker logs nextcloud-app
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.5. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.5. Set the 'ServerName' directive globally to suppress this message
[Fri Dec 31 22:21:20.143397 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.51 (Debian) PHP/8.0.14 configured -- resuming normal operations
[Fri Dec 31 22:21:20.143420 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
[Fri Dec 31 22:25:55.546887 2021] [mpm_prefork:notice] [pid 1] AH00170: caught SIGWINCH, shutting down gracefully
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.5. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.5. Set the 'ServerName' directive globally to suppress this message
[Fri Dec 31 22:26:39.802918 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.51 (Debian) PHP/8.0.14 configured -- resuming normal operations
[Fri Dec 31 22:26:39.802939 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
[Fri Dec 31 22:39:48.694182 2021] [mpm_prefork:notice] [pid 1] AH00170: caught SIGWINCH, shutting down gracefully
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.5. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.5. Set the 'ServerName' directive globally to suppress this message
[Fri Dec 31 22:40:32.317318 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.51 (Debian) PHP/8.0.14 configured -- resuming normal operations
[Fri Dec 31 22:40:32.317431 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

config.php:

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'instanceid' => 'oc8b0f2fhqxu',
  'passwordsalt' => 'salt',
  'secret' => 'secret',
  'trusted_domains' => 
  array (
    0 => 'lan ip:port',
    1 => 'nextcloud.example.com',
    2 => 'localhost',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '22.0.0.11',
  'overwrite.cli.url' => 'https://nextcloud.example.com',
  'overwritehost' => 'nextcloud.example.com',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => 'db',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'user',
  'dbpassword' => 'secret',
  'installed' => true,
  'mail_from_address' => 'me',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'example.com',
  'mail_smtpsecure' => 'ssl',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp.email.com',
  'mail_smtpname' => 'me@example.com',
  'mail_smtppassword' => ' secret',
  'twofactor_enforced' => 'true',
  'twofactor_enforced_groups' => 
  array (
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
  ),
  'mail_smtpport' => 'smtpport',
  'mail_smtpstreamoptions' => 
  array (
    'ssl' => 
    array (
      'allow_self_signed' => true,
      'verify_peer' => false,
      'verify_peer_name' => false,
    ),
  ),
  'maintenance' => false,
  'filelocking.enabled' => false,
  'updater.secret' => 'secret',
);

nginx container:

Warning: A custom dhparam.pem file was provided. Best practice is to use standardized RFC7919 DHE groups instead.                                             
forego      | starting dockergen.1 on port 5000                                                                                                               
forego      | starting nginx.1 on port 5100                                                                                                                   
nginx.1     | 2021/12/31 22:40:31 [notice] 19#19: using the "epoll" event method                                                                              
nginx.1     | 2021/12/31 22:40:31 [notice] 19#19: nginx/1.21.5                                                                                                
nginx.1     | 2021/12/31 22:40:31 [notice] 19#19: built by gcc 10.3.1 20211027 (Alpine 10.3.1_git20211027)                                                    
nginx.1     | 2021/12/31 22:40:31 [notice] 19#19: OS: Linux 5.4.0-91-generic                                                                                  
nginx.1     | 2021/12/31 22:40:31 [notice] 19#19: getrlimit(RLIMIT_NOFILE): 1048576:1048576                                                                   
nginx.1     | 2021/12/31 22:40:31 [notice] 19#19: start worker processes                                                                                      
nginx.1     | 2021/12/31 22:40:31 [notice] 19#19: start worker process 24
nginx.1     | 2021/12/31 22:40:31 [notice] 19#19: start worker process 25
dockergen.1 | 2021/12/31 22:40:31 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
dockergen.1 | 2021/12/31 22:40:31 Watching docker events
dockergen.1 | 2021/12/31 22:40:31 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: signal 1 (SIGHUP) received from 28, reconfiguring
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: reconfiguring
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: using the "epoll" event method
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: start worker processes
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: start worker process 41
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: start worker process 42
nginx.1     | 2021/12/31 22:40:32 [notice] 24#24: gracefully shutting down
nginx.1     | 2021/12/31 22:40:32 [notice] 24#24: exiting
nginx.1     | 2021/12/31 22:40:32 [notice] 24#24: exit
nginx.1     | 2021/12/31 22:40:32 [notice] 25#25: gracefully shutting down
nginx.1     | 2021/12/31 22:40:32 [notice] 25#25: exiting
nginx.1     | 2021/12/31 22:40:32 [notice] 25#25: exit
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: signal 17 (SIGCHLD) received from 25
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: worker process 25 exited with code 0
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: signal 29 (SIGIO) received
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: signal 17 (SIGCHLD) received from 24
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: worker process 24 exited with code 0
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: signal 29 (SIGIO) received
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: signal 1 (SIGHUP) received from 43, reconfiguring
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: reconfiguring
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: using the "epoll" event method
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: start worker processes
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: start worker process 55
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: start worker process 56
nginx.1     | 2021/12/31 22:40:32 [notice] 42#42: gracefully shutting down
nginx.1     | 2021/12/31 22:40:32 [notice] 41#41: gracefully shutting down
nginx.1     | 2021/12/31 22:40:32 [notice] 41#41: exiting
nginx.1     | 2021/12/31 22:40:32 [notice] 42#42: exiting
nginx.1     | 2021/12/31 22:40:32 [notice] 41#41: exit
nginx.1     | 2021/12/31 22:40:32 [notice] 42#42: exit
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: signal 17 (SIGCHLD) received from 42
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: worker process 42 exited with code 0
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: signal 29 (SIGIO) received
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: signal 17 (SIGCHLD) received from 41
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: worker process 41 exited with code 0
nginx.1     | 2021/12/31 22:40:32 [notice] 19#19: signal 29 (SIGIO) received
nginx.1     | nextcloud.example.com LANIP - - [31/Dec/2021:22:50:55 +0000] "GET / HTTP/2.0" 500 177 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0" "-"
(more 500's like above)

Maybe Redis (if you are using it) or the database are not already up&running when the nextcloud container is coming up. do you have a “depends on” statement in your docker-compose file to tell docker to wait for these two container before starting nextcloud?

Thanks for the response - I’m not using Redis, and the NC container depends on the other three - proxy, db and ssl.

I also successfully spun up the containers with the same compose file on a new host, but with a different distro, so maybe not the positive I want it to be.

When I attempt to use the cli commands, I’m getting an error consistently that indicates a problem with the database:

root@cfea8c8a4929:/var/www/html# php ./occ maintenance:repair [224/224]
An unhandled exception has been thrown:
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘nextcloud.oc_appconfig’ doesn’t e
xist in /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Connection.php:82
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Connection.php(82): PDO->query(‘SELECT * FROM ...' ) #1 /var/www/html/3rdparty/doctrine/dbal/src/Connection.php(1062): Doctrine\DBAL\Driver\PDO\Connection->que ry('SELECT * FROM …’)
#2 /var/www/html/lib/private/DB/Connection.php(236): Doctrine\DBAL\Connection->executeQuery(‘SELECT * FROM
...', Array, Array, NULL) #3 /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\DB\Connection->executeQuery('S ELECT * FROM …’, Array, Array)
#4 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(287): Doctrine\DBAL\Query\QueryBuilder->exec
ute()
#5 /var/www/html/lib/private/AppConfig.php(344): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/html/lib/private/AppConfig.php(109): OC\AppConfig->loadConfigValues()
#7 /var/www/html/lib/private/AppConfig.php(300): OC\AppConfig->getApps()
#8 /var/www/html/lib/private/legacy/OC_App.php(972): OC\AppConfig->getValues(false, ‘installed_versi…’)
#9 /var/www/html/lib/private/Server.php(691): OC_App::getAppVersions()
#10 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(160): OC\Server->OC{closure}(Objec
t(OC\Server))
#11 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleCont
ainer->OC\AppFramework\Utility{closure}(Object(Pimple\Container))
#12 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(127): Pimple\Container->offsetGet(’
OC\Memcache\Fac…‘)
#13 /var/www/html/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query(‘OC
\Memcache\Fac…’, false)
#14 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(56): OC\ServerContainer->query(‘OC
\Memcache\Fac…’)
#15 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(182): OC\AppFramework\Utility\Simpl
eContainer->get(‘OC\Memcache\Fac…’)
#16 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(160): OC\AppFramework\Utility\Simpl
eContainer->OC\AppFramework\Utility{closure}(Object(OC\Server))
#17 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleCont
ainer->OC\AppFramework\Utility{closure}(Object(Pimple\Container))
#18 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(127): Pimple\Container->offsetGet(’
OCP\ICacheFacto…')

Searching through the forums, it seems similar another issue. I confirmed that my config.php is being auto-generated in the container. The /var/www/html directory had permissions for www-data:root, so I tried chown’ing to www-data:www-data, but I’m still getting the same errors.

There’s another similar issue that suggests manually setting up a different missing table here.

Are there any resources available for steps to manually re-create the table for nextcloud.oc_appconfig?

I have been testing in a different nextcloud server, and the same table oc_appdata also does not exist in that instance’s database, but it does not throw errors regarding the missing table when using the occ commands. Any thoughts?