Install Magento 2 module from github or bitbucket repository using composer

October 30, 2015  |  No Comments  |  by Raj (MagePsycho)  |  Magento 2

In previous article, we discussed about How to install Magento 2 on MEMP (Mac OS X + Nginx + MySQL + PHP-FPM) stack using Composer

In this article we will discuss on How to install Magento 2 modules from any github or bitbucket repositories.

Let’s say we have Easy Template Path Hints (a Magento 2 module used for triggering the template path hints on the fly) on github.

Install Module

In order to install the Easy Template Path Hints Module from Github, run the following commands:

composer config repositories.magesycho-magento2-easy-template-path-hints git git@github.com:MagePsycho/magento2-easy-template-path-hints.git
composer require magepsycho/magento2-easy-template-path-hints:dev-master

Breakdown

1. Registering the module git repository

composer config repositories.magesycho-magento2-easy-template-path-hints git git@github.com:MagePsycho/magento2-easy-template-path-hints.git

Composer config repository command syntax:

composer config repositories.<unique-repo-name> <vcs-type> <vcs-url-https-or-sshl>

Composer will register a new repository to composer.json (under “repositories” node). Updated composer.json looks like:

{  
  "repositories": {
    "magesycho-magento2-easy-template-path-hints": {
      "type": "git",
      "url": "git@github.com:MagePsycho/magento2-easy-template-path-hints.git"
    }
  }
}

2. Registering the module package itself

composer require magepsycho/magento2-easy-template-path-hints:dev-master

Composer require command syntax:

composer require <vendor>/<package>:dev-<branch>

This will add new dependent package under node “require” as:

{
  "name": "magento/magento2ce",
  "description": "Magento 2 (Community Edition)",
  "type": "project",
  "require": {
    "magepsycho/magento2-easy-template-path-hints": "dev-master"
  }
}

followed by Module installation from the repo.

Install Magento 2 Module from Github

Install Magento 2 Module from Github

Few Notes:
This approach will only work for the modules which has been packaged with composer.json
Please read more on Packaging a Magento 2 Module

If you are loading a package from VCS repository (git, svn etc.), version should be a branch name prefixed with ‘dev-‘ else you may get error like

The requested package magepsycho/magento2-easy-template-path-hints could not be found in any version, there may be a typo in the package name.

Source: https://getcomposer.org/doc/05-repositories.md#vcs

Enable Module

After the module has been downloaded from git repository, Module needs to be enabled.
1. Disable the cache under System->Cache Management
2. Run following Commands

php bin/magento module:enable MagePsycho_Easypathhints --clear-static-content
php bin/magento setup:upgrade

Go to Admin menu > Stores > Configuration, you will be able to see the ‘Easy Template Path Hints’ settings:

Easy Template Path Hints - Backend Settings

Easy Template Path Hints – Backend Settings

Disable Module

In order to disable the Module, simply run:

php bin/magento module:disable --clear-static-content MagePsycho_Easypathhints

That’s all.
Isn’t that more easier/powerful way of installing, enabling or disabling the Magento 2 Modules than Magento 1?

Posted in Magento 2 and tagged , , , . Bookmark the permalink.

About Raj (MagePsycho)

Raj, the guy behind MagePsycho is a Zend PHP5 Certified Engineer, Magento Certified Developer, Magento Moderator / Freelancer with specialization in web applications (CMS, E-Commerce, ERP etc.). Catch him on: Twitter: @magepsycho Skype: magentopycho