How to Install Magento 2 via Composer

Just like Magento 1, the installation of Magento 2 can also be done via a composer. This is the most effective way to install as well as support/upgrade Magento 2. All files, modules, and libraries are automatically copied and prepared for setup via composer.

In order to install Magento 2 via composer, follow the below steps:

Composer project creation

The Magento 2 Community Edition 2.4.2 can be set up in the current directory using the below command:

composer create-project --repository-url= magento/project-community-edition:2.4.2 . --prefer-dist --ignore-platform-reqs --no-interaction --dev

Magento version 2.4.2 can be changed to any other accessible Magento 2 version ( such as magento 2.2.0, 2.3.5, 2.4.2, etc) by changing the parameter ”--repository-url”.

Setting Up Magento 2

Once you have copied Magento via composer, you must run Magento's own setup command below:

php -f setup:install --base-url="" --db-host="" --db-name= --db-user= --db-password= --admin-firstname="Admin" --admin-lastname="Admin" --admin-email="[email protected]" --admin-user="admin" --admin-password="" --use-rewrites="1" --backend-frontname="admin" --db-prefix=mage_

For this command, there are some parameters that you need to specify (or you can simply replace default values, mentioned above):

  • db - database name, which already should be created
  • db-user - database user
  • db-password - database password
  • password - password to Magento 2 admin


If you follow the above steps, Magento will be installed correctly.


Categories: Tech Questions