How to install magento 2 via composer

Unlike Magento 1, Magento 2 can be installed via composer. It’s most faster and stable way to install and further support/upgrade Magento 2. Composer will automatically copy all required files, modules, libraries and prepare all things for setup.

To install Magento 2 via composer, you need to follow these steps:

Creating Composer project

The following command will setup Magento 2 Community Edition 2.2.5 in current directory:

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

You can change version 2.2.5 to any other available Magento 2 version (2.1.0, 2.1.3, 2.2.4, etc) by adjusting --repository-url parameter.

Setting Up Magento 2

After copying Magento via composer, you need to run Magento´s own setup command:

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

In this command, you need to specify the following parameters (or just replace default values, shown above):

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

These steps will make clean Magento 2 install.