Magento – What are the best practices for installing third party extensions in Magento 2

best practicecomposermagento2

While working on a client project for Magento 2 – I've discovered numerous methods of loading in and keeping track of third party extensions.

Going into this assuming that we're using the integrator installation method (composer!), what are the best practices for managing third party extensions?

So far, every extension I've purchased or downloaded has had it's own composer.json file – and I know of at least three different ways extension authors would recommend to install their extension:

  1. Copy these files into app/code
  2. Copy this zip into folder, add it is a artifact repository, and require it
  3. Add this online repository (with/without auth) and require it

So far, I've come across 1 & 2 and am just sort of suspecting #3 exists. But then, noticing that the ones that suggested #1 I found that you can have a "path" repository – moved my extensions from app/code to the same folder I decided to put these artifacts, and required it that way.

In this process, my repositories configuration looks something like:

"repositories": {
    "0": {
        "type": "composer",
        "url": "https://repo.magento.com/"
    },
    "artifacts": {
        "type": "artifact",
        "url": "artifacts"
    },
    "third-party": {
        "type": "path",
        "url": "artifacts/*/*"
    },
},

So my question to you is – what is the best practice here? How do you manage third party extensions?

So far I believe the way I am doing it is the best way – if only because their composer.json gets read and any dependency conflicts (or PHP version constraints) will become apparent – but I don't think that's definitive enough.

Best Answer

  • Install module via composer is the best way to Magento 2. Becuase there are many advantages if we install module via composer.

  • If you want to upgrade module you just need to change the version in composer.json file and run composer update command at the rootMagentoento.

  • While in manual installation you need to first download module and replace old files and run setup:upgrade command to upgrade module.

  • All modules which are installed via composer are downloaded in vendor folder.

  • Magento uses default https://repo.magento.com/ URL to download module If you purchase module from Magento Marketplace.

  • If you purchase module from third-party website. You need to add a repository in composer.json to download and install a module.

For Example

"repositories": {
    "0": {
        "type": "composer",
        "url": "https://repo.magento.com/" //Default Magento Repositry
    },
    "thirdparty-module": {
        "type": "composer",
        "url": "https://mymodule.thirdparty.com/" //Third Party Repositary
    }
},

In my opinion composer is the best and proper way to install module in Magento 2.

Install Third Party Module Via composer:

  1. Run this command to add new repository in conposer.json

composer config repositories.thirdparty-module git https://thirdparty-composer-url.com

  1. Now run this command to add component and version of module in composer.json

composer require [component-name]:[version]

Forex.  composer require prince/helloword:1.0.0
  1. Now run composer update to download module from repository.

composer update

  1. Now run setup:upgrade to install and register module in config.php

php bin/magento setup:upgrade

Related Topic