Installing on Apache with MySQL 8

Hey guys,

I’m trying to install Nextcloud to my Linux using Apache 2.4 with PHP 8 and MySQL, I put the database info in config.php, even created a user just for it in MySQL, but Apache error log keeps saying it failed to connect to database, do I have to go back to PHP 7 in order for it to work? or nextcloud should work with PHP 8?


It should work with php 8.0. For php 8.1, you need to wait for NC 24 (expected next month).

If you change the php version, make sure all dependencies are fullfilled:

In this case the error should say something like module not found.

I don’t know what I’m doing wrong, but I went back to PHP 7.4, installed all the modules in that page, I made sure the user for the nextcloud database could access it via phpMyAdmin, but apache error log still says that nextcloud failed to connect to the database, this is frustrating.

This is what the Apache log tells me: [proxy_fcgi:error] [pid 3927:tid 140076306646784] [client] AH01071: Got error ‘PHP message: {“reqId”:“H7ZxAOwz4L5GnWe7A6WO”,“level”:3,“time”:“March 31, 2022 18:25:12”,“remoteAddr”:“”,“user”:"–",“app”:“index”,“method”:“GET”,“url”:"/nextcloud/index.php",“message”:“Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] “,“userAgent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0”,“version”:””,“exception”:{“Exception”:“Doctrine\\DBAL\\Exception”,“Message”:“Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] “,“Code”:2002,“Trace”:[{“file”:”/var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php”,“line”:1519,“function”:“connect”,“class”:“OC\\DB\\Connection”,“type”:"->"},{“file”:"/var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php",“line”:1041,“function”:“getWrappedConnection”,“class”:“Doctrine\\DBAL\\Connection”,“type”:"->"},{“file”:"/var/www/html/nextcloud/lib/private/DB/Connection.php",“line”:237,“function”:“executeQuery”,“class”…’, referer:

I have my connection type set to mysql and the dbuser can access the database in mysql using phpMyAdmin, I don’t understand why nextcloud can’t connect to mysql.

And your database is running? Does it work from command line?
Can you check the database log, perhaps credentials that are not accepted etc.?

Database server is running, I can connect to it from console:

mysql -u nextcloud -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 685
Server version: 8.0.28-0ubuntu0.20.04.3 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

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


MySQL log doesn’t show anything regarding nextcloud’s credentials, everything looks ok for the nextcloud user to connect to the database, but it’s not happening from nextcloud, it does happen from phpMyAdmin, only nextcloud can’t connect to the database apparently.

Does it make a difference if you install from command line?

Tried that too, I get this:

An unhandled exception has been thrown:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] in /var/www/html/nextcloud/lib/private/DB/Connection.php:87
Stack trace:
#0 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1519): OC\DB\Connection->connect()
#1 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1041): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /var/www/html/nextcloud/lib/private/DB/Connection.php(237): Doctrine\DBAL\Connection->executeQuery()
#3 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\DB\Connection->executeQuery()
#4 /var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(287): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /var/www/html/nextcloud/lib/private/AppConfig.php(361): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/html/nextcloud/lib/private/AppConfig.php(126): OC\AppConfig->loadConfigValues()
#7 /var/www/html/nextcloud/lib/private/AppConfig.php(317): OC\AppConfig->getApps()
#8 /var/www/html/nextcloud/lib/private/App/AppManager.php(127): OC\AppConfig->getValues()
#9 /var/www/html/nextcloud/lib/private/App/AppManager.php(216): OC\App\AppManager->getInstalledAppsValues()
#10 /var/www/html/nextcloud/lib/private/legacy/OC_Template.php(283): OC\App\AppManager->isEnabledForUser()
#11 /var/www/html/nextcloud/lib/base.php(744): OC_Template::printErrorPage()
#12 /var/www/html/nextcloud/lib/base.php(1087): OC::init()
#13 /var/www/html/nextcloud/console.php(48): require_once(’/var/www/html/n…’)
#14 /var/www/html/nextcloud/occ(11): require_once(’/var/www/html/n…’)

You didn’t say what linux distro you’re using. For example, Debian is notorious for defaulting to old application versions that might not work with PHP8.

You also didn’t say what Nextcloud version you’re using. Nextcloud 22, for example, won’t work with PHP8.

This is why there’s a template to guide you in asking for help!

At first I was using Ubuntu Server 21.10, but I went back to 20.04 so I’m using Ubuntu Server 20.04 and Nextcloud 23.0.3 with PHP 7.4.

I changed the title because it ran on Ubuntu 21.10 using SQLite3 and PHP 8, but not with MySQL, so something must be wrong with how Nextcloud connects to a MySQL database.

Is the database existing and noted in config.php? Does the nextcloud user have full rights on the database? What port is mysql running on?

It does exist and it’s configured in config.php, but while I was searching for how Nextcloud connects to MySQL y found it tries to use the old mysql_connect function that was deprecated since PHP 5.5.0 and I believe is not used in PHP 7 anymore, instead mysqli_connect must be used.

I searched for mysqli_connect in Nextcloud files and I didn’t find any.

That must be the reason why it doesn’t connect to MySQL.