Besides installing Magento 2 extensions via SSH manually, installing via composer is another very common and simple way used by a lot of Magento users.
In this article, we will provide you with step-by-step instructions on how to get a Magento 2 extension installed on the website by Composer.
Now, let’s start with us!
Step 1: Create Access Keys And Get The Package Information
Send us an email to firstname.lastname@example.org along with the order number. We will create access keys as per your requirement and then provide you with information about the packages.
Step 2: Configure Composer Repository
Firstly, you need to add a new composer repository to the BSSCommerce Composer Repository.
Type the following command in the root directory of Magento:
composer config repositories.bsscommerce composer <path>
In the path indicate:
- https://composer.bsscommerce.com/community – for Community extensions.
- https://composer.bsscommerce.com/enterprise – for Enterprise extensions.
Step 3: Install Extension
A - Install a whole package/kit/combo or individual extension
Once you have the package name and version, install the Magento 2 extension by executing the following command:
composer require package_name - For the latest version
composer require package_name:version - For the older versions
For example, you want to install the BSS One Step Checkout extension, please execute the following command:
- For the latest version:
composer require bsscommerce/module-one-step-checkout
- For version 2.1.2:
composer require bsscommerce/module-one-step-checkout:2.1.2
When you run this command for the first time, CLI will ask you to enter the Username and Password. Please fill in the access key created in Step 1.
Note: The Public key corresponds to the Username, and the Private key corresponds to the Password.
Composer will inform a message to you. If you want to save the Access key, please type Y.
In case you already saved the Access key in the server, but you want to use another Access key, do the following:
Open the file ~/.composer/auth.json and delete the username/password of the corresponding repository:
Then you install the module as usual:
php bin/magento setup:upgrade
Note: In case of occurring error, it could be that the Access key you entered is wrong, your account does not have access to this package, or the version you entered does not exist.
- If you want to update the latest version of the extension, run this command:
composer update package_name
- If you want to remove the extension, run this command:
composer remove package_name
- If you want to update another version, not the latest version of the extension, run this command:
composer remove package_name
composer require package_name: version
Note: If you installed extensions via SSH (by uploading the package) before, then when updating the extension via composer, running the command setup:upgrade will fail. In this case, you have to delete the folder you uploaded in app/code/…
B - install individual extensions with multiple branches
With extensions that have multiple branches, the guide for installing via Composer is a bit different.
When you update to the latest version in a branch,please run this command for new code update:
composer require <package_name>:dev-<branch_name> --prefer-dist
Branch_name: usually corresponds to the Magento edition/version that the module supports.
For example: Current branches of Magento 2 Multiple Store View Pricing (Community Edition) are as follow:
|Branch Name||Magento Version Applied|
|CE-2.3.5||M2.3.5 and M2.4.0|
|CE-2.4.5||M2.4.5 and above|
If your store is using Magento CE version 2.4.x, you will run this command:
composer require bsscommerce/multi-store-pricing-set:dev-CE-2.4.1 --prefer-dist
Note: Branches (if exist) will be listed on the Installation Guide of the extension. Please go to Installation Guide of the extension to find details.
To remove extension, you can still apply the same remove command as section A: composer remove package_name
C - Install specific extensions within a package/kit/combo
This section is only useful if you want to install the specific extensions within a package/kit/combo, e.g. you want to test some specific functions first, or there are some extensions you do not want to install at all.
- To install particular modules within a package, you just have to install them separately:
composer require bsscommerce/add-multiple-products
The version to be installed will be the latest version.
- To remove specific modules, similarly, you remove them separately:
composer remove bsscommerce/add-multiple-products
d - Install Hyva compatibility modules
Installation via composer will run the command:
composer require package-name:dev-hyva-master --prefer-dist
For the case of installing a package/kit/combo, you can only choose one among these 2 options: install the whole package or install individual extensions. Using both ways may result in some issues.
If you already followed one approach, and want to switch to the other, you need to run the remove command first.
This is a complete installation process you can follow to have a Magento 2 module on your website.
Thanks for reading our article! Hope it is helpful for you!