MySQL server has gone away. Nextcloud ignoring database configuration in `config.php`

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 21.0.0-4
Operating system and version (eg, Ubuntu 20.04): 5.10.16-arch1-1
Apache or nginx version (eg, Apache 2.4.25): nginx 1.18.0-2
PHP version (eg, 7.4): 8.0.2-1

The issue you are facing:
I upgraded existing nextcloud install today. I this also required me to upgrade from php7 to php8. The upgrade wiped my configuration file. Any page I go to gives 500. Any occ command gives MySQL server has gone away. I am watching the logs of mariadb with journalctl -u mariadb -f.
Every time I run an occ command, I see [Warning] Aborted connection 21 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication),
even though I have dbname, dbuser, and dbpassword set in /etc/webapps/nextcloud/config.php and /etc/webapps/nextcloud/config/config.php.

I also tried changing the dbtype to sqlite3 and I don’t get any logs at all in mariadb,
so the config file is doing something.

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

Steps to replicate it:

  1. Update existing nextcloud install to 21
  2. Set dbuser and everything correctly in /etc/webapps/nextcloud/config.php
  3. Run sudo /usr/bin/runuser -u nextcloud -- /usr/bin/php /usr/share/webapps/nextcloud/occ upgrade or similar

The output of your Nextcloud log in Admin > Logging:
I can’t get into the website at all, but here is the tail of /var/log/nextcloud.log http://ix.io/2Q8o

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

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

Feb 20 19:34:19 cencored systemd[1]: Started A high performance web server and a reverse proxy server.

Hi i just wanted to share that I’m having the same exact problem and well ‘fixed’ it.
I’ve gone as far as to start from scratch and completely wipe everything off nextcloud of my installation yet the error occurs.

A heads up prior to updating would have been nice (somewhere like your blog or changelog) now i’m left with a broken installation, i’d rather have kept NC20 till this installation was stable. Though i might just revert back for the time being…

I cannot find any logs just this output from “occ upgrade”:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2006] MySQL server has gone away in /usr/share/webapps/nextcloud/lib/private/DB/Connection.php:85
Even after setting the correct database and user i get the same error:
mariadbd[444]: 2021-02-21 11:52:30 291 [Warning] Aborted connection 291 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)

anyway the ‘fix’? Delete config.php from config folder. (or rename it). then you can run occ commands just fine. I found this out whilst writing this post actually, i’m still getting 500 errors on the nextcloud pages so I need to find out how to fix that but I hope this little step helps you as well.

Update: after deleting config.php, nextcloud realises it needs to be installed and shows you the setup screen instead of a 500 error…

Thanks for the answer KaasKop but that did not work for me.

It seems like you’re using the example config.php and changed some parameters. As far as I know it is not recommended to do this. Nextcloud should create a simple and small config.php during installation.

Thank you for your answer. I still don’t get why it isn’t working though and why a config.php that used to work would stop working.

I tried moving the config.php file to another name and still internal server error.

I solved it. It was a permission issue. The update changed the owner of /etc/webapps/nextcloud and /var/lib/nextcloud to nextcloud:nextcloud but php was running as http. This is one of the first things I tried, but I missed one directory so it still errored out so I assumed it was something else and went down a different path.

Once I fixed the owners, I moved config.php and nextcloud did its initial setup. I put in the database information, but the wizard failed because my user already exists (duh it’s an existing install that you borked). I went into config.php and added 'installed' => true and everything works.