Trying to install sample module in Magento 2 from this. Below is the module structure app/code/NameSpace/Module/

module image


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Magentostudy_News" setup_version="0.0.1" schema_version="0.0.1"/>


    "name": "magentostudy/module-news",
    "description": "N/A",
    "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "magento/module-store": "100.0.0",
        "magento/module-email": "100.0.0",
        "magento/module-ui": "100.0.0",
        "magento/framework": "100.0.0"
    "type": "magento2-module",
    "version": "0.0.1",
    "license": [
    "autoload": {
        "files": [ "registration.php" ],
        "psr-4": {
            "Magentostudy\\News\\": ""



Executing below command to enable module

php ./bin/magento module:enable Magentostudy_News

It says there are no commands defined in the "module" namespace. Also on frontend it throws below exception. I am using composer but not github.

Fatal error: Uncaught exception 'Magento\Framework\Exception\LocalizedException' with message 'Source class "\Magento\Framework\Module\Updater\Setup" for "Magento\Framework\Module\Updater\SetupFactory" generation does not exist.'


Added Setup folder with file InstallSchema.php which includes below code

 * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)

/* @var $installer \Magento\Setup\Module\SetupModule */

namespace Magentostudy\News\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

$installer = $this;

 * Creating table magentostudy_news
$table = $installer->getConnection()->newTable(
    ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
    'Entity Id'
    ['nullable' => true],
    'News Title'
    ['nullable' => true,'default' => null],
    ['nullable' => true,'default' => null],
    ['nullable' => true,'default' => null],
    'News image media path'
    ['nullable' => false],
    'Created At'
    ['nullable' => true,'default' => null],
    'World publish date'
    ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
    'News item'
  1. What is the correct way to install Magento 2 modules ?
  2. Any crucial step I missed ?

Reference URL : http://mageinferno.com/blog/setting-up-magento-2-module-right-way-composer-packagist


1 Answer 1


You can install Magento 2 extension easily from any VCS (github or bitbcuket) if the module is packed with proper composer.json file.

For example, in order to install Easy Template Path Hints 2 extension, you just have to run two commands for installation:

composer config repositories.magesycho-magento2-easy-template-path-hints git [email protected]:MagePsycho/magento2-easy-template-path-hints.git
composer require magepsycho/magento2-easy-template-path-hints:dev-master


1> Registering the module git repository

composer config repositories.magesycho-magento2-easy-template-path-hints git [email protected]:MagePsycho/magento2-easy-template-path-hints.git

Composer config repository command syntax looks like:

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": "[email protected]: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"

and download the module from the repo.

And if you have extension zip file, just extract it and copy it to the app/code/ folder - as that simple.

Once the Module is installed, you can simply enable it using following commands:

php bin/magento module:enable MagePsycho_Easypathhints --clear-static-content
php bin/magento setup:upgrade
  • Can you please explain a bit more about the role of composer config and require here? How does it work?
    – amitshree
    Dec 29, 2015 at 14:05
  • 1
    @amitshree updated!
    – MagePsycho
    Dec 29, 2015 at 14:13
  • @MagePsycho, what if I need to develop a simple hello world module without github or bitbcuket OR a client specific module which will not be on and VCS ? The point here is to have a clear and correct approach to install Magento 2 modules and also to avoid any pitfalls. It would be great if you could shed some light. Dec 30, 2015 at 4:55
  • @Vikram Please check if that sounds helpful.
    – MagePsycho
    Dec 30, 2015 at 6:29
  • 1
    @MagePsycho so custom code written for almost every custom site-build out there belongs in app/code/ ? Moreover, do all modules regardless of location, should have a composer.json and a registration.php ? Dec 30, 2015 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.