"Internal Server Error" after rebooting rPi server. error.log says "PHP Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_appconfig' doesn't exist..."

Hi guys, I’m in way over my head.

I installed nextcloud on a Raspberry Pi 4B 4GB model according to these instructions.

Everything was working GREAT until I decided to reboot the server tonight (since I had applied some updates and wanted to make sure everything would continue working ok).

I’ve got lots of linux experience, a tiny bit of apache experience, and zero database experience.

Thanks in advance for any assistance given. I’m out of my element :smirk:

Chewie

further details

systemctl status
chewie@nextcloud:apache2$ systemctl status apache2
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-04-11 21:57:24 CDT; 57min ago
     Docs: https://httpd.apache.org/docs/2.4/
 Main PID: 723 (apache2)
    Tasks: 8 (limit: 4915)
   CGroup: /system.slice/apache2.service
           ├─  723 /usr/sbin/apache2 -k start
           ├─15275 /usr/sbin/apache2 -k start
           ├─15276 /usr/sbin/apache2 -k start
           ├─15277 /usr/sbin/apache2 -k start
           ├─15278 /usr/sbin/apache2 -k start
           ├─15279 /usr/sbin/apache2 -k start
           ├─15283 /usr/sbin/apache2 -k start
           └─15294 /usr/sbin/apache2 -k start

Apr 11 21:57:23 nextcloud systemd[1]: Starting The Apache HTTP Server...
Apr 11 21:57:24 nextcloud apachectl[565]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.
Apr 11 21:57:24 nextcloud systemd[1]: Started The Apache HTTP Server.
Apr 11 22:00:23 nextcloud systemd[1]: Reloading The Apache HTTP Server.
Apr 11 22:00:24 nextcloud apachectl[12853]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.
Apr 11 22:00:24 nextcloud systemd[1]: Reloaded The Apache HTTP Server.
chewie@nextcloud:apache2$ systemctl status mariadb
● mariadb.service - MariaDB 10.3.27 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-04-11 22:22:48 CDT; 32min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 14399 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
  Process: 14400 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 14402 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -e
  Process: 14480 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 14482 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
 Main PID: 14449 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 32 (limit: 4915)
   CGroup: /system.slice/mariadb.service
           └─14449 /usr/sbin/mysqld

Apr 11 22:22:47 nextcloud mysqld[14449]: 2021-04-11 22:22:47 0 [Note] /usr/sbin/mysqld (mysqld 10.3.27-MariaDB-0+deb10u1) starting as process 1
Apr 11 22:22:47 nextcloud mysqld[14449]: 2021-04-11 22:22:47 0 [Warning] Could not increase number of max_open_files to more than 16384 (reques
Apr 11 22:22:48 nextcloud systemd[1]: Started MariaDB 10.3.27 database server.
Apr 11 22:22:48 nextcloud /etc/mysql/debian-start[14484]: Upgrading MySQL tables if necessary.
Apr 11 22:22:48 nextcloud /etc/mysql/debian-start[14487]: /usr/bin/mysql_upgrade: the '--basedir' option is always ignored
Apr 11 22:22:48 nextcloud /etc/mysql/debian-start[14487]: Looking for 'mysql' as: /usr/bin/mysql
Apr 11 22:22:48 nextcloud /etc/mysql/debian-start[14487]: Looking for 'mysqlcheck' as: /usr/bin/mysqlcheck
Apr 11 22:22:48 nextcloud /etc/mysql/debian-start[14487]: This installation of MySQL is already upgraded to 10.3.27-MariaDB, use --force if you
Apr 11 22:22:48 nextcloud /etc/mysql/debian-start[14495]: Checking for insecure root accounts.
Apr 11 22:22:48 nextcloud /etc/mysql/debian-start[14499]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables

Nextcloud version (eg, 20.0.5): 21.0.0
Operating system and version (eg, Ubuntu 20.04): Raspbian GNU/Linux 10 (buster)
Apache or nginx version (eg, Apache 2.4.25): 2.4.38
PHP version (eg, 7.4): 7.3

The issue you are facing:
Getting “Internal Server Error” after rebooting.
Error.log says:

[Sun Apr 11 22:45:59.276427 2021] [php7:error] [pid 14543] [client 192.168.1.203:58148] PHP Fatal error:  Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_appconfig' doesn't exist in /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Driver/PDO/Connection.php:82\nStack trace:\n#0 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Driver/PDO/Connection.php(82): PDO->query('SELECT * FROM `...')\n#1 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1035): Doctrine\\DBAL\\Driver\\PDO\\Connection->query('SELECT * FROM `...')\n#2 /var/www/html/nextcloud/lib/private/DB/Connection.php(226): Doctrine\\DBAL\\Connection->executeQuery('SELECT * FROM `...', Array, Array, NULL)\n#3 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(210): OC\\DB\\Connection->executeQuery('SELECT * FROM `...', Array, Array)\n#4 /var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(286): Doctrine\\DBAL\\Query\\QueryBuilder->execute()\n#5 /var/www/html/nextcloud/lib/private/AppConfig.php(345): OC\\DB\\QueryBuilder\\QueryBuilder->execute()\n#6 /var/www/html/nextcloud/lib/ in /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php on line 47

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

Steps to replicate it:

  1. Rebooted server
  2. (Tried restarting Apache2)
  3. (Tried restarting MariaDB)

The output of your Nextcloud log in Admin > Logging:

(can't get to it)

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

<?php
$CONFIG = array (
  'instanceid' => 'ocekb6u17vtf',
  'passwordsalt' => 'redacted',
  'secret' => 'redacted',
  'trusted_domains' => 
      [
       'nextcloud',
       'redacted-hostname.hopto.org'
      ],
  'datadirectory' => '/var/www/html/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '21.0.0.18',
  'overwrite.cli.url' => 'https://nextcloud/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'ncuser',
  'dbpassword' => 'redacted',
  'installed' => true,
);

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

[Sun Apr 11 22:50:59.279966 2021] [php7:error] [pid 14556] [client 192.168.1.203:58198] PHP Fatal error:  Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_appconfig' doesn't exist in /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Driver/PDO/Connection.php:82\nStack trace:\n#0 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Driver/PDO/Connection.php(82): PDO->query('SELECT * FROM `...')\n#1 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1035): Doctrine\\DBAL\\Driver\\PDO\\Connection->query('SELECT * FROM `...')\n#2 /var/www/html/nextcloud/lib/private/DB/Connection.php(226): Doctrine\\DBAL\\Connection->executeQuery('SELECT * FROM `...', Array, Array, NULL)\n#3 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(210): OC\\DB\\Connection->executeQuery('SELECT * FROM `...', Array, Array)\n#4 /var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(286): Doctrine\\DBAL\\Query\\QueryBuilder->execute()\n#5 /var/www/html/nextcloud/lib/private/AppConfig.php(345): OC\\DB\\QueryBuilder\\QueryBuilder->execute()\n#6 /var/www/html/nextcloud/lib/ in /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php on line 47
[Sun Apr 11 22:51:08.134349 2021] [mpm_prefork:notice] [pid 723] AH00173: SIGHUP received.  Attempting to restart
[Sun Apr 11 22:51:08.252708 2021] [ssl:warn] [pid 723] AH01909: 127.0.0.1:443:0 server certificate does NOT include an ID which matches the server name
[Sun Apr 11 22:51:08.271000 2021] [mpm_prefork:notice] [pid 723] AH00163: Apache/2.4.38 (Raspbian) OpenSSL/1.1.1d configured -- resuming normal operations
[Sun Apr 11 22:51:08.271253 2021] [core:notice] [pid 723] AH00094: Command line: '/usr/sbin/apache2'
[Sun Apr 11 22:51:29.282241 2021] [php7:error] [pid 15277] [client 192.168.1.203:58206] PHP Fatal error:  Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_appconfig' doesn't exist in /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Driver/PDO/Connection.php:82\nStack trace:\n#0 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Driver/PDO/Connection.php(82): PDO->query('SELECT * FROM `...')\n#1 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1035): Doctrine\\DBAL\\Driver\\PDO\\Connection->query('SELECT * FROM `...')\n#2 /var/www/html/nextcloud/lib/private/DB/Connection.php(226): Doctrine\\DBAL\\Connection->executeQuery('SELECT * FROM `...', Array, Array, NULL)\n#3 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(210): OC\\DB\\Connection->executeQuery('SELECT * FROM `...', Array, Array)\n#4 /var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(286): Doctrine\\DBAL\\Query\\QueryBuilder->execute()\n#5 /var/www/html/nextcloud/lib/private/AppConfig.php(345): OC\\DB\\QueryBuilder\\QueryBuilder->execute()\n#6 /var/www/html/nextcloud/lib/ in /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php on line 47

I think I see where the issue might be, but I have NO idea how I got here, or what to do from here:

chewie@nextcloud:~$ sudo mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 831
Server version: 10.3.27-MariaDB-0+deb10u1 Raspbian 10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| nextcloud          |
| performance_schema |
+--------------------+
4 rows in set (0.001 sec)

MariaDB [(none)]> use nextcloud;
Database changed
MariaDB [nextcloud]> show tables;
Empty set (0.001 sec)

MariaDB [nextcloud]> 

Ok, I figured it out.

At some point, I had put everything in /var under a separate mountpoint, but somehow, I had already created the database within the root filesystem’s /var.

So, I had to copy /var/lib/mysql from the root filesystem onto the secondary disk’s /lib/mysql (normally mounted under /var), and that fixed it.

Thank God. :sweat_smile: