Connection refused from within nextcloud web app but works from shell

When I am trying to run

sudo -u www-data /var/www/html/nextcloud/occ vitachaos -n --path=vitachaos/files/Educational/

I am getting the following error:

An unhandled exception has been thrown:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] Connection refused in /var/www/html/nextcloud/lib/private/DB/Connection.php:85
Stack trace:
#0 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1486): OC\DB\Connection->connect()
#1 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1014): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /var/www/html/nextcloud/lib/private/DB/Connection.php(226): Doctrine\DBAL\Connection->executeQuery()
#3 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(210): 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(345): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/html/nextcloud/lib/private/AppConfig.php(110): OC\AppConfig->loadConfigValues()
#7 /var/www/html/nextcloud/lib/private/AppConfig.php(301): OC\AppConfig->getApps()
#8 /var/www/html/nextcloud/lib/private/legacy/OC_App.php(965): OC\AppConfig->getValues()
#9 /var/www/html/nextcloud/lib/private/Server.php(682): OC_App::getAppVersions()
#10 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(155): OC\Server->OC\{closure}()
#11 /var/www/html/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#12 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(122): Pimple\Container->offsetGet()
#13 /var/www/html/nextcloud/lib/private/ServerContainer.php(137): OC\AppFramework\Utility\SimpleContainer->query()
#14 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(56): OC\ServerContainer->query()
#15 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(177): OC\AppFramework\Utility\SimpleContainer->get()
#16 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(155): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#17 /var/www/html/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#18 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(122): Pimple\Container->offsetGet()
#19 /var/www/html/nextcloud/lib/private/ServerContainer.php(137): OC\AppFramework\Utility\SimpleContainer->query()
#20 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(56): OC\ServerContainer->query()
#21 /var/www/html/nextcloud/lib/private/Server.php(1031): OC\AppFramework\Utility\SimpleContainer->get()
#22 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(155): OC\Server->OC\{closure}()
#23 /var/www/html/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#24 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(122): Pimple\Container->offsetGet()
#25 /var/www/html/nextcloud/lib/private/ServerContainer.php(137): OC\AppFramework\Utility\SimpleContainer->query()
#26 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(56): OC\ServerContainer->query()
#27 /var/www/html/nextcloud/lib/private/Server.php(1990): OC\AppFramework\Utility\SimpleContainer->get()
#28 /var/www/html/nextcloud/lib/private/Files/View.php(119): OC\Server->getLockingProvider()
#29 /var/www/html/nextcloud/lib/private/Server.php(430): OC\Files\View->__construct()
#30 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(155): OC\Server->OC\{closure}()
#31 /var/www/html/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#32 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(122): Pimple\Container->offsetGet()
#33 /var/www/html/nextcloud/lib/private/ServerContainer.php(137): OC\AppFramework\Utility\SimpleContainer->query()
#34 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(56): OC\ServerContainer->query()
#35 /var/www/html/nextcloud/lib/private/Server.php(1353): OC\AppFramework\Utility\SimpleContainer->get()
#36 /var/www/html/nextcloud/lib/base.php(588): OC\Server->boot()
#37 /var/www/html/nextcloud/lib/base.php(1076): OC::init()
#38 /var/www/html/nextcloud/console.php(49): require_once('...')
#39 /var/www/html/nextcloud/occ(11): require_once('...')

although i can login from the shell of the same host using:

mysql -u nextcloud -P 6036 -p

and it works. I am using 6036 as port address.

then I checked db accessing from root user:

>  SHOW GRANTS FOR nextcloud;
+----------------------------------------------------------------------------------------------------------+
| Grants for nextcloud@%                                                                                   |
+----------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'nextcloud'@'%' IDENTIFIED BY PASSWORD '*285CACEB5CAB2A414BC5581C7F65B97C56CB8808' |
| GRANT ALL PRIVILEGES ON `nextcloud`.* TO 'nextcloud'@'%'                                                 |
+----------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

users:

+-----------+-----------+-------------------------------------------+
| user      | host      | password                                  |
+-----------+-----------+-------------------------------------------+
| nextcloud | %         | *285CACEB5CAB2A414BC5581C7F65B97C56CB8808 |
+-----------+-----------+-------------------------------------------+

why am I getting connection refused ?

I have the same issue. Any solutions?

Without more details it’s impossible to say.

Post:

  • your config (output of occ config:list system)
  • the exact log entry or stack trace you’re seeing

Also check your nextcloud.log for clues as to when the problem started. It may help you isolate the underlying cause.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.