Magento 2 Installation Glitch: `setup:install` Fails with Existing `env.php` and Empty Database
Unraveling a Persistent Magento 2 Installation Glitch: When `setup:install` Meets an Empty Database
As e-commerce migration experts at Shopping Mover, we often encounter various intricacies and challenges within the Magento ecosystem. One such scenario, recently highlighted in a GitHub issue, brings to light a peculiar bug affecting the core installation process of Magento 2. This issue specifically targets developers and system administrators who might be working with fresh database instances while attempting to reuse an existing app/etc/env.php file.
The Core Problem: `setup:install` Command Failure
The reported bug, identified as Issue #40931, describes a situation where the setup:install command, crucial for setting up a Magento instance, fails under specific conditions. The scenario unfolds as follows:
- A Magento 2 instance (specifically reproduced on 2.4-develop) is initially installed, creating the
app/etc/env.phpconfiguration file. - Subsequently, the database associated with this installation is entirely deleted (e.g., for a fresh start, testing, or development reset).
- An attempt is then made to run the
setup:installcommand again, expecting a clean re-installation into the now-empty database.
Instead of a smooth re-installation, users are met with a cryptic error message:
In WebsiteRepository.php line 153:
The default website isn't defined. Set the website and try again.
This error indicates that even though the database is empty, Magento's setup process, when encountering an existing env.php, incorrectly assumes certain database structures or data (like the default website) should already be present. This leads to a halt in the installation, preventing a fresh setup.
Steps to Reproduce the Issue
For those looking to understand or verify this bug, the steps are straightforward:
- Install Magento using the
setup:installcommand. - Delete the database (e.g., using SQL commands):
drop database magento; create database magento; - Attempt to run the
setup:installcommand again.
The expected outcome would be a successful re-installation. However, the actual result is the aforementioned "default website isn't defined" error.
Community Insights and Status
The issue was reported by swnsma and quickly gained traction. The Magento Community Engineering team, specifically engcom-Bravo, successfully reproduced the bug on the latest 2.4-develop instance, confirming its validity. This confirmation is a crucial step in the bug resolution process, ensuring that the issue is acknowledged and added to the development backlog. A Jira issue (AC-17525) has also been created to track its progress internally within Adobe Commerce.
While the thread confirms the bug, it does not provide an immediate workaround or solution within the comments. This means developers encountering this issue currently need to find their own methods to proceed, such as manually removing the app/etc/env.php file before a fresh installation, or restoring a database backup if available. The bug is classified with a Severity S2, indicating it affects non-critical functionality but forces users to employ a workaround.
For Magento users, especially those involved in continuous development, testing, or migration projects where database resets are common, this issue highlights the importance of understanding Magento's installation lifecycle and potential edge cases. Staying informed about such confirmed bugs is vital for maintaining smooth operations and efficient project delivery.