Magento 2 Enable custom module

The following command works all the time, if the module is disabled. Otherwise something is wrong with module or it is already enabled. But If you’re reading blog article about how to enable custom module, probably, something is going wrong there. In this article I will cover a few the most common mistakes, usually made creating new custom module. I hope it helps you to force it work.

Magic command to enable module in Magento 2

bin/magento module:enable Vendor_CustomModule

Module file structure

One of the most common problem – the module can be located in wrong directory and when it is the time to registry your custom module, Magento 2 system can’t find them. There are only two files which could be related on this problem.

app/code/Magetrend/HelloWorld/registration.php
app/code/Magetrend/HelloWorld/etc/module.xml
Magento 2 base module file structure

Make sure these two files are located in the right directory. Here “Magetrend” is Vendor and “HelloWorld” module name.

Naming and CamelCase mistakes

There are 3 places where we have to check extension name. As you probably saw already, in this article examples, I’m using Magetrend_HelloWorld module.

1. Mistake in file structure. The correct module files path is

 app/code/Magetrend/HelloWorld/

where the word “World” begins with uppercase W. It might be that your path is like:

app/code/Magetrend/Helloworld/

which is incorrect and it could be the reason why your custom module is not working.

2. Mistake in registration.php file. Open this this file and check the extension name.

3. Mistake in module.xml file. Open this this file and check the extension name.

Check module status

If we already have double checked the things above, now it is time to check module status. The following ssh command will do the trick:

bin/magento module:enable Magetrend_HelloWorld

and what we expect is

in case if you will get the response from server which says “Module is disabled”, you have to run the ssh command, to enable module, from which I began this article:

bin/magento module:enable Magetrend_HelloWorld

And here is the end. It looks nothing special, but you have to check these thing carefully. Nothing will change if you will miss one of them. As always, I would be more than happy to get your feed back in the comments bellow and append this article with your case.

Happy coding guys!

Leave a Comment