Categories
Magento 2

Magento 2 – Create a New Module / Extension

How to Create Module or Extension in Magento 2 Completed Guide. We know whole Magento 2 system is built with different unique Magento system core modules. Magento is opensource eCommerce platform, So we can add/install our developed custom module on Magento project.

In this article today I discuse how to create new custom Module or Extension for Magento 2. For Magento 2 module create we need to complete the following steps:

  • 1. Create vendor directory
  • 2. Create module directory
  • 3. Create etc/module.xml file
  • 4. Create registration.php file
  • 5. Create composer.json file
  • 6. Create etc/adminhtml/system.xml file
  • 7. Run php bin/magento setup:upgrade command to install the new module
  • 8. Check your created new module is working

Module Folder and Files structure

Let’s go through complete each of above steps.

Create vendor directory

Go to app/code directory on your Magento 2 project and create a directory rename it to as your module vendor name. I have create a directory “ExtendFeature” is vendor.

Create module directory

Go to app/code/ExtendFeature directory on your Magento 2 project and create a directory rename it to as your module name. I have create a directory “HelloWorld” is my custom module name.

Create etc/module.xml file

Go to app/code/ExtendFeature/HelloWorld directory on your Magento 2 project and create a directory rename it to etc, Now go to etc directory and crete module.xml file. Each Magento 2 module must have this file.

Open module.xml file and add following code.

Create registration.php file

Go to app/code/ExtendFeature/HelloWorld directory on your Magento 2 project and create a PHP file rename it to registration.php. Each Magento 2 module must have this file.

Open registration.php file and add following code.

Create composer.json file

Go to app/code/ExtendFeature/HelloWorld directory on your Magento 2 project and create a composer.json file.

Open composer.json file and add following code.

Create etc/adminhtml/system.xml file

Now create system.xml file in etc/adminhtml/ directory, Open system.xml file and add following code. This file generated some fields on Magento 2 system configuration section. You can view configuration fields by admin menu STORE=>Configurations=>Extend Feature menu.

Run php bin/magento setup:upgrade command to install the new module

Now login into SSH terminal and go to Magento 2 project root directory and run following commands to install/active your new module.

Check your created new module is working

Each Magento 2 module after install/active by command setup:upgrade added a new line on app/etc/config.php file, Now please check the file app/etc/config.php. New module is listed by auto-generated modules that are active. Please never change config list manually!

Also check module status via SHELL command.

After apply these steps, you can successfully create/active a new module in Magento 2 project and enjoy!

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE