Magento 2 Modules – Where Do Third Party Modules Go?

magento2module

I just installed the first official release of Magento 2. I was surprised to find that the app/code folder was gone

app/code

This was for both the version downloaded from the website and the version installed via composer. Also, when I tried to manually create the app/code folder, and then do a php bin/magento module:enable Pulsestorm_MyModule to enable a sample module, I got the following error

 Unknown module(s): 'Pulsestorm_MyModule'

Where are third party modules supposed to live? If the answer is "a source repository and installed via composer", how does a module developer need to structure their modules to live in a Magento 2 repository?

Best Answer

Preferably 3PLs will live in the vendor directory along with everything else. However… :) We all know there is typically custom code written for almost every custom site-build out there, and this IMO belongs in app/code/ still. Yes, you can still run a module from app/code.

All modules, regardless of location, should have a composer.json and a registration.php file which are used to get the module into the system. You also need the etc/modules.xml file. This is, technically, all it takes to register a module:

$ tree app/code/Alger/
app/code/Alger/
└── Skeleton
    ├── composer.json
    ├── etc
    │   └── module.xml
    └── registration.php

2 directories, 3 files

To get the module up and running, you need to run setup:upgrade and then cache:flush for the system to both recognize and load your new component:

$ bin/magento module:enable Foo_Bar
$ bin/magento setup:upgrade -q && bin/magento cache:flush -q

Update: Two methods to install module from public GitHub repo: https://gist.github.com/davidalger/77761f13d9752b117f35

Related Topic