We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
- Home
- Blog
- eCommerce Talk
- How to install Magento 2 via composer
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.3.4 can be set up in the current directory using the below command:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition:2.3.4 --prefer-dist --ignore-platform-reqs --no-interaction --dev
Version 2.3.4 can be changed to any other accessible Magento 2 version (2.3.0, 2.3.7, 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 bin/magento setup:install --base-url=http://localhost.com/ \
--db-host=localhost --db-name=<db> --db-user=<db-user> --db-password=<db-password> \
--admin-firstname=Magento --admin-lastname=User [email protected] \
--admin-user=admin --admin-password="<password>" --language=en_US \
--currency=USD --timezone=America/Chicago --use-rewrites=1 \
--search-engine=elasticsearch7 --elasticsearch-host=<elasticsearch-host> \
--elasticsearch-port=<elasticsearch-port>
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
- elasticsearch-host - Host of Elastic Search
- elasticsearch-port - Port of Elastic Search
If you follow the above steps, Magento will be installed correctly.