I downloaded magento 2-2.4.1.zip. Unzipped it to /var/www/html/magento24/ - my local folder for local domain http://magento24.local configured by nginx on ubuntu20.04.

I had done composer update or install and next use this command:

bin/magento setup:install --base-url=http://magento24.local \
 --db-host=localhost --db-name=magento24 --db-user=user24 --db-password=1234 \
 --admin-firstname=Magento --admin-lastname=User [email protected] \
 --admin-user=admin --admin-password=test1234 --language=en_US \
 --currency=USD --timezone=America/Chicago --use-rewrites=1

This stopped on step 4:

[Progress: 4 / 818]
Installing database schema:

In WebsiteRepository.php line 159:
  The default website isn't defined. Set the website and try again.  

I tried different way. To download magento2.4.1 by composer from magento repository:

php /bin/composer1/composer.phar create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.1 .

But this first throw problems with composer version (first i use coimposer 2.0.x, next uses 1.0.0alpha - different errors php7.3 and php7.1 fpm)


9 Answers 9


It appears that this error might appear when a MySQL database is empty, but the env.php file is present. (Possibly because you had setup Magento, but for some reason, database was deleted.)

To fix this you can add --cleanup-database flag to setup:install command (For me, it went ok only after the second try.), or delete the env.php file indeed, which I don't recommend.


php bin/magento setup:install \
      --base-url=http://www.magento.lan \
      --db-host=localhost \
      --db-name=db_magento \
      --db-user=magento \
      --db-password=magento@123 \
      --admin-firstname=magento \
      --admin-lastname=Admin \
      [email protected] \
      --admin-user=magento \
      --admin-password=magento@123 \
      --language=en_US \
      --currency=USD \
      --timezone=America/Chicago \
      --use-rewrites=1 --cleanup-database
  • 1
    I confirm that this problem occurs if you have an empty database and env.php exists. Commented Nov 28, 2023 at 21:39

I was changing a db and removing env.php helped to get rid of the error for me.

  • Thank you, deleting the previous app/etc/env.php fixed the problem
    – snez
    Commented Feb 26, 2021 at 10:57

=>>> DELETE env.php file ..its work

After run this command

php bin/magento setup:install --base-url="http://localhost/magento4" --db-host="localhost" --db-name="magento4" --db-user="root" --db-password= --admin-user="admin" --admin-password="admin@123" --admin-firstname="admin12" --admin-lastname="user" --admin-email="[email protected]" --backend-frontname="admin"


I finally managed to to work this:

Use composer version 1.9.0:

1. Instal composer 1.9. Or You can downgrade it.

  • cd /var/www/html/mag241/

  • php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

  • sudo php composer-setup.php --install-dir=/bin/composer19 --version=1.9.0

2. Use composer 1.9 to get magento2.4.1.

  • php /bin/composer19/composer.phar create-project
    --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.1 .

3. Run bin/magento setup:install with Your database adres login and url

  • php bin/magento setup:install --base-url=http://magento24.local/
    --db-host=localhost --db-name=magento24 --db-user=user24 --db-password=1234 --admin-firstname=Magento --admin-lastname=User [email protected] --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --search-engine=elasticsearch7 --elasticsearch-host=es-host.example.com --elasticsearch-port=9200

It occurs if default website's data is not found which is stored in [store_website]. That means Magento site can't connect to database or database tables. For my case, I installed Magento with "m_" prefix for tables, then I changed its database whose tables doesn't have any prefix. So, to fix this issue, I modified:

'table_prefix' => 'm_' to 'table_prefix' => '' in app/etc/env.php


Its a table prefix mentioned in env.php, that works for me after update.

Thanks Ravi P


I faced this issue while trying to run the integration tests,

For those who are getting this error after trying to run the integration tests. I faced this issue since in one of my local modules I was using some classes as a dependency injection but Magento couldn't find that class so I kept getting that error.

It is fixed for me just by using Proxy instead of that class directly as a dependency injection.

  • I believe your issue was a different case. Yes, proxies solvie issues with command lines that use dependency injections that connect to the database. Commented Nov 28, 2023 at 21:41

In my case, it was the table_prefix not declared in my env.php and the idiot person who initially created the db I was using, created the db with prefixes.


In these cases you need to move code folder outside app folder and try again and after finish you can put it back

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.