Create a Magento Module

Module is a structural element of Commerce – the whole system is built upon modules. Typically, the first step in creating a customization is building a module. In this post, We explain how to create a module. Subscribe to Bnethos for all the Magento2 problems and customizations.

Steps to add a module

  • Create the module folder.
  • Create the etc/module.xml file.
  • Create the registration.php file.
  • Create composer.json(optional)
  • Run the bin/magento setup:upgrade.
  • Check that the module is enabled.
Step 1: Create the module folder.

To build a module in Magento 2, you need to understand the architecture of the module directory. Magento 2 architecture has two locations to create the module: app/code folder and the vendor folder.

In Magento 2, all the core modules located at vendor folders come under the installation of Magento 2. If you are building any overriding existing functionality or customizing the core module or creating a new module you can use app/code folder

Name of the module is defined as VendorName_ModuleName. First part is name of the vendor(i.e) the company name or the vendor name and last part is name of the module(i.e)Short name of the functionality of the moudle. For example: Bnethos_ModuleCreation

Step 2: Create the etc/module.xml file.

Declare the created Magento 2 module by using the configuration file. During the Magento 2 module development, the file system searches for the module’s configuration found in the, etc directory of the module. The module.xml examines the declaration of the Name of your component.

setup_version is required to manage the setup of the installation and upgrade processes for your component.

sequence determines the dependencies of other modules if your module depends on other components.
Create a module.xml under:

This file contains information about the Module Name, Module Version, and dependencies of other modules. 

Contents would be:

Step 3: Create the registration.php file.

Components, including modules, themes, and language packages, must be registered in the system through the ComponentRegistrar class.

Each component must have a file called registration.php in its root directory. Create a registration.php under

Contents would be:

Create composer.json(optional)

Magento use Composer, a PHP dependency manager, to package components and product editions. Composer reads a composer.json file in the application’s root directory to download third-party dependencies listed in the file. This file is very much useful if you a merchant who sells a module. Create a composer.json under

Here is an example of the composer.json file.

Step 4: Run the bin/magento setup:upgrade.

Running upgrade command makes your new module active, notifying Magento of its presence.

Step 5: Check that the module is enabled.

Run the below command to check the created module is enabled or not.

The above command will result the status of the module like.

If it is showing disabled. you can use the below command to enable the module

Or another way, you can access the file app/etc/config.php where you can find your module’s status in the list of other modules.

And here you go, these steps can lead you to successfully create a new custom module in Magento 2.

If you need more help regarding this post, feel free to ask in the Comments section below.

I would be happy to solve your queries.

16 thoughts on “Create a Magento Module”

Leave a Comment