Internal server error - DB connection issue / PHP issue?

Nextcloud version (eg, 20.0.5): 22.2.3
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): Apache
PHP version (eg, 7.4): 7.4

The issue you are facing:

Hi everyone. After searching the forum and using google for hours the last 2 days and not finding a solution that works I am trying to put the issue out here and see if anyone else has an idea.

I noticed when cleaning my install that my trash bin actually never deletes files for good. So I see multiple thousand files that are years old in my instances trash bin. Stupid as I am I click on “mark all” and hit delete.

Since this, the instance is broken. Idk if it ever finished deleting (the trash bin folder seems to still contain tons of files looking at it on the shell)

I only get the internal server error message.

So far I could figure out that it has to be an issue with MySQL or PHP as I have found tons of errors in the nextcloud log that state these kinds of entries: (See logging down below)

But I also came across entries stating

“No such file or directory in /var/www/nextcloud/lib/private/DB/Connection.php”


“General error: 2006 MySQL server has gone away nextcloud”

I am beyond lost as to what the issue could be and I am a little confused as to what I need to provide for your alls better understanding. Please let me know what you need.

As a side note: I have been having issues with MySQL binlog files getting out of hand. I did a purge for those files (the proper way via MySQL command) before this happened. It is important to note that the instance did work after that purge as I could navigate to the trash bin and delete it. Just then it stopped working.

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

The output of your Nextcloud log in Admin > Logging:

  "reqId": "kz8JqNUExCwq471tgjlA",
  "level": 3,
  "time": "2021-12-31T16:56:57+00:00",
  "remoteAddr": "",
  "user": "--",
  "app": "base",
  "method": "DELETE",
  "url": "/index.php/apps/bookmarks/public/rest/v2/lock",
  "message": "Failed to start session",
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0",
  "version": "",
  "exception": {
    "Exception": "Exception",
    "Message": "Failed to start session",
    "Code": 0,
    "Trace": [
        "file": "/var/www/nextcloud/lib/base.php",
        "line": 423,
        "function": "__construct",
        "class": "OC\\Session\\Internal",
        "type": "->"
        "file": "/var/www/nextcloud/lib/base.php",
        "line": 645,
        "function": "initSession",
        "class": "OC",
        "type": "::"
        "file": "/var/www/nextcloud/lib/base.php",
        "line": 1089,
        "function": "init",
        "class": "OC",
        "type": "::"
        "file": "/var/www/nextcloud/index.php",
        "line": 34,
        "args": [
        "function": "require_once"
    "File": "/var/www/nextcloud/lib/private/Session/Internal.php",
    "Line": 62,
    "CustomMessage": "--"

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

$CONFIG = array (
  'instanceid' => 'xxx',
  'passwordsalt' => 'xxx',
  'secret' => 'xxx',
  'trusted_domains' => 
  array (
    0 => '',
    1 => 'xxx',
    2 => 'xxx',
  'datadirectory' => '/mnt/cloud',
  'dbtype' => 'mysql',
  'version' => '',
  'overwrite.cli.url' => '',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextclouduser',
  'dbpassword' => 'xxx',
  'installed' => true,
  'htaccess.RewriteBase' => '/',
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'tls',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'xxx',
  'mail_from_address' => 'develop',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'xxx',
  'mail_smtpname' => 'xxx',
  'mail_smtppassword' => 'xxx',
  'maintenance' => false,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'theme' => '',
  'logfile' => '/var/www/nextcloud.log',
  'loglevel' => 2,
  'default_phone_region' => 'DE',
  '' => 'stable',
  'forwarded_for_headers' => 
  array (
  'trusted_proxies' => '',
  'app_install_overwrite' => 
  array (
    0 => 'passman',

Short update:

From my limited understanding, I would almost guess that it has to be a PHP issue.

The DB is there, intact, the user is available and there seems to be no issue with MySQL at all.

Since PHP is used to create a connection with MySQL my thought is that there is something wrong with that.
Nextcloud log (after clearing) show exclusive errors regarding PHP as shown in the original post.
From failed GET to DELETE requests.

I really hope someone has come across this and/or has any idea on what I could do.
For now, I’ll proceed to check if I can see any issues with PHP (or maybe the apache2?)

Happy new year y’all! :smiley:

Have you tried rescanning the filesystem to pick up any changes?

sudo -u www-data php occ files:scan --all

Or files:cleanup to delete file entries with no matching entries in the storage table?

Hey mainland!

Thanks for your response.
That did unfortunately not work either.

I just used this situation to do a fresh install of this rather old instance and updated to a fresh version 23. Thanks to great infos here in there forum I had no issue still saving my password manager and news. My cloud is locally synced anyway. Pain in the ass to re-sync 3TB but oh well.

At least nothing is lost.

I still appreciate the help.