Reading list Switch to dark mode

    Magento 2 Development 04: Module Registration

    Updated 3 August 2023


    In this blog, we will learn how to create and register a Module in Magento.

    In Magento, a module is a standalone unit where we write our functionalities or business logic to achieve our goal.

    It is a group of directories that contain the blocks, controllers, helpers, and models needed to create a specific store feature. It is the unit of customization in the Magento platform.

    Magento modules can be created to perform multiple functions, from influencing user experience to changing storefront appearance. They can install, deleted, or disabled.

    Steps to Create a Module

    • Create the module folder.
    • Create the registration.php file.
    • Create the module.xml file.
    • Run the command: php bin/magento setup:upgrade
    • Run the command: php bin/magento setup:di:compile

    Create the module Folder

    Now to create the module we have to create a vendor folder first with the vendor name (which is Webkul in our case) under the app/code folder.

    Searching for an experienced
    Magento 2 Company ?
    Find out More

    (if the code folder is not available then please create it).

    Then we have to create the module folder “BlogManager” (the module name).

    Folder Structure

    Now our folder structure should be like (app/code/Webkul/BlogManager). Where Webkul is our Vendor name and BlogManager is our Module name.

    Create the registration.php file

    After this, we have to create a registration.php file under the file path (app/code/Webkul/BlogManager) so that Magento can recognize it as a module and register it.

    Code for app/code/Webkul/BlogManager/registration.php file


    Types of components are,
    i) Module
    ii) Theme
    iii) Language
    iv) Library

    Folder structure

    Create the module.xml file.

    To create the module.xml file, we first need to create an etc folder under the directory (app/code/Webkul/Blogmanager), and in the etc folder we need to create a module.xml file with the following content.

    Code for etc/module.xml file

    <?xml version="1.0"?>
    <config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Webkul_BlogManager">
    Folder structure
    For better understanding

    Run the command: php bin/magento setup:upgrade

    After creating these two files we need to run the setup upgrade command like below in the terminal at the Magento root folder. It will activate the module.

    php bin/magento setup:upgrade

    This command is used to update the Magento database schema and data, as well as apply any necessary system upgrades. It is used in the Magento 2 upgrade process and ensures that your Magento store runs smoothly with the latest updates and features.

    Run the command: php bin/magento setup:di:compile

    It is used to compile code like Factories, Proxies, Interceptors, etc., and puts them in the generated directory.

    php bin/magento setup:di:compile

    Folder Structure till now

    Folder Structure

    Next blog -> Magento 2 Development 05: Route Management and Controllers

    Previous blog -> Magento 2 Development 03: Area codes

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home