magento2: Connection "default" is not defined

getting Connection “default” is not defined when we run magento setup:upgrade in dockerfile. Below is my dockerfile

FROM bitnami/magento:2.4.2 WORKDIR opt/bitnami/magento COPY . . RUN composer require --no-update --dev magento/ece-tools magento/magento-cloud-docker RUN composer update RUN composer install RUN magento module:enable --all RUN magento setup:upgrade RUN magento setup:di:compile

Please help me in fixing this

Summary: Cannot install Magento without workaround mentioned above Environment: Any Linux system, dockerized or not

Steps to reproduce:

  1. create project with minimal composer.json and run composer install
{
    "type": "project",
    "minimum-stability": "dev",
    "prefer-stable": true,
    "require": {
        "magento/product-community-edition": "2.4.5-p1"
    },
    "config": {
        "use-include-path": true,
        "allow-plugins": {
            "magento/*": true,
            "laminas/laminas-dependency-plugin": true,
            "cweagans/composer-patches": true,
            "dealerdirect/phpcodesniffer-composer-installer": true,
            "phpro/grumphp-shim": true,
            "phpstan/extension-installer": true
        },
        "preferred-install": "dist",
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "Magento\\Setup\\": "setup/src/Magento/Setup/"
        },
        "files": [
            "app/etc/NonComposerComponentRegistration.php"
        ],
        "exclude-from-classmap": [
            "**/dev/**",
            "**/update/**"
        ]
    },
    "repositories": {
        "magento-marketplace": {
            "type": "composer",
            "url": "https://repo.magento.com/",
            "only": [
                "amzn/*",
                "dotmailer/*",
                "klarna/*",
                "magento/*",
                "msp/*",
                "paypal/*",
                "temando/*",
                "vertex/*",
                "yotpo/*"
            ]
        }
    },
    "extra": {
        "magento-force": "override"
    },
    "version": "2.4.5-p1"
}
  1. check out app/etc/config.php with module information from a previously completed installation
  2. run setup:install, e.g.
bin/magento setup:install --backend-frontname "admin" --db-host "db" --db-user "magento" --db-password "magento" --db-name "magento" --skip-db-validation --base-url="https://demo-magento2.lh/" --use-secure "1" --base-url-secure "https://demo-magento2.lh/" --search-engine "elasticsearch7" --elasticsearch-host "elasticsearch" --elasticsearch-port "9200" --elasticsearch-index-prefix "magento2" --admin-user "magento" --admin-password "magento123" --admin-email "info@example.com" --admin-firstname "Admin" --admin-lastname "User" --amqp-host="" --amqp-port="" --amqp-user="" --amqp-password="" --cleanup-database

Expected result: installation succeeds

Actual result: The following output

Starting Magento installation:
File permissions check...
[Progress: 1 / 1032]
Required extensions check...
[Progress: 2 / 1032]
Enabling Maintenance Mode...
[Progress: 3 / 1032]
Installing deployment configuration...
[Progress: 4 / 1032]
Cleaning up database...
Cleaning up database `magento`
[Progress: 5 / 1032]
Installing database schema:
Schema creation/updates:
Module 'Magento_Store':

...

[Progress: 1029 / 1032]
Disabling Maintenance Mode:
In ResourceConnection.php line 148:                                       
  Connection "default" is not defined  

it is interesting though that with this minimal composer.json the error comes at the end when disabling maintenance mode, the database schema is already created at this point and following up with bin/magento setup:upgrade succeeds.

my previous issue happens with a more extensive composer.json where some default extensions and packages are installed together with Magento. I will try to narrow down the culprit

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 26 (14 by maintainers)

Most upvoted comments

Same issue here on Magento 2.4.4 (Open Source) + PHP 8.1

[Progress: 1018 / 1023]
Installing admin user...
[Progress: 1019 / 1023]
Caches clearing:
Cache cleared successfully
[Progress: 1020 / 1023]
Disabling Maintenance Mode:
In ResourceConnection.php line 148:
                                       
  [DomainException]                    
  Connection "default" is not defined  
                                       
Exception trace:
  at /phpapp/vendor/magento/framework/App/ResourceConnection.php:148
 Magento\Framework\App\ResourceConnection->getConnectionByName() at /phpapp/generated/code/Magento/Framework/App/ResourceConnection/Interceptor.php:41
 Magento\Framework\App\ResourceConnection\Interceptor->getConnectionByName() at /phpapp/vendor/magento/framework/App/ResourceConnection.php:97
 Magento\Framework\App\ResourceConnection->getConnection() at /phpapp/generated/code/Magento/Framework/App/ResourceConnection/Interceptor.php:23
 Magento\Framework\App\ResourceConnection\Interceptor->getConnection() at /phpapp/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php:312
 Magento\Framework\Model\ResourceModel\Db\AbstractDb->getConnection() at /phpapp/vendor/magento/module-message-queue/Model/ResourceModel/Lock.php:103
 Magento\MessageQueue\Model\ResourceModel\Lock->releaseOutdatedLocks() at /phpapp/vendor/magento/module-message-queue/Model/Plugin/ResourceModel/Lock.php:39
 Magento\MessageQueue\Model\Plugin\ResourceModel\Lock->afterSet() at /phpapp/vendor/magento/framework/Interception/Interceptor.php:146
 Magento\Framework\App\MaintenanceMode\Interceptor->Magento\Framework\Interception\{closure}() at /phpapp/vendor/magento/framework/Interception/Interceptor.php:153
 Magento\Framework\App\MaintenanceMode\Interceptor->___callPlugins() at /phpapp/generated/code/Magento/Framework/App/MaintenanceMode/Interceptor.php:32
 Magento\Framework\App\MaintenanceMode\Interceptor->set() at /phpapp/setup/src/Magento/Setup/Model/Installer.php:1467
 Magento\Setup\Model\Installer->setMaintenanceMode() at n/a:n/a
 call_user_func_array() at /phpapp/setup/src/Magento/Setup/Model/Installer.php:385
 Magento\Setup\Model\Installer->install() at /phpapp/setup/src/Magento/Setup/Console/Command/InstallCommand.php:238
 Magento\Setup\Console\Command\InstallCommand->execute() at /phpapp/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /phpapp/vendor/symfony/console/Application.php:1009
 Symfony\Component\Console\Application->doRunCommand() at /phpapp/vendor/symfony/console/Application.php:273
 Symfony\Component\Console\Application->doRun() at /phpapp/vendor/magento/framework/Console/Cli.php:115
 Magento\Framework\Console\Cli->doRun() at /phpapp/vendor/symfony/console/Application.php:149
 Symfony\Component\Console\Application->run() at /phpapp/bin/magento:23

Please stop assuming if one does not react within 14 days that the issue is “solved”. Especially if a number of people have encountered the same issue.

Can reproduce this issue with Magento 2.4.4 + PHP 8.1 In fact, it is completely impossible to install Magento from scratch without having various problems:

- [Progress: 1437 / 1440]
Disabling Maintenance Mode:
In ResourceConnection.php line 148:
  [DomainException]                    
  Connection "default" is not defined  

After running the installation again - without touching anyting - the process completes. BUT…

Then we have a redirection loop to /setup

This is totally insane how this framework is working… Event with the option cleanup-database you can have multiple issues trying to rerun the setup. Like “entity 1 not defined” and some other craps. This is by far the worst developer experience I ever had!

I could trace down this error at the end to a pre-existing app/etc/config.php. We use this for some default configuration but even if it just contains the modules info (exactly like after a complete installation), the error comes at the end of a new installation. Updating the comment above…

That gives us another possible workaround: delete app/etc/config.php and restore it after installation

I still try to find out what can cause the error at the beginning of the setup, no solution for that yet

Hi,

Got the same issue while installing Magento 2.4.4 and PHP 8.1.

Any help? on this

image

It may be permission related issue. For quick fix comment below line. After completing installation you have to disable maintenance mode. $script[] = [‘Disabling Maintenance Mode:–’, ‘setMaintenanceMode’, [0]]; https://github.com/magento/magento2/blob/2.4.4/setup/src/Magento/Setup/Model/Installer.php#L371

Thanks @schmengler for the reply!

Your use case seems valid to me. Hence confirming this issue.

Thanks

@engcom-Hotel thanks and yes I do:

This is simulating setup on a new environment using an existing project repository with config.php but without env.php

or to be more specific, the actual steps are:

  • Magento is set up initially on environment A (e.g. developer machine)
  • app/etc/config.php is committed to Git, app/etc/env.php not because it is environment specific
  • Repository is checked out on environment B (e.g. other developer’s machine), now there’s no env.php yet and an empty database
  • initial installation on environment B fails

I had the same issue. Deleting the database and recreate it before running the install seems to solve it.

Hi,

Got the same issue while installing Magento 2.4.4 and PHP 8.1.

Any help? on this

image

Hi Got the same issue. I am trying on Ubuntu machine Magento 2.4.4 + PHP 8.1.

[Progress: 1316 / 1319] Disabling Maintenance Mode:

In ResourceConnection.php line 148:

Connection “default” is not defined