Create the module directory: In your Magento 2 installation, navigate to the app/code
directory and create a new directory for your module. For example, let’s call it Lokesh_MyModule
- Create the
module.xml
file: Inside theLokesh_MyModule
directory, create a file namedmodule.xml
with the following code.
Path :- app/code/Lokesh/MyModule/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Lokesh_MyModule" setup_version="1.0.0"/>
</config>
In above code, replace Lokesh_MyModule
with your vendor and module name you want to use.
Create the registration.php
file: Inside the Lokesh_MyModule
directory, create a file named registration.php
with the following code.
Path :- app/code/Lokesh/MyModule/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Lokesh_MyModule',
__DIR__
);
Make sure to replace Lokesh_MyModule
with your vendor and module name you want to use.
your file structure will look like this:-
├── app
│ └── code
│ └── Lokesh <---- VendorName
│ └── MyModule <-- ModuleName
│ ├── etc
│ │ └──module.xml
│ │
│ └── registration.php
│
Verify the module registration: To ensure that the module is registered correctly, run the following command from your Magento 2 root directory:
php bin/magento module:status
You will see your custom module listed with the status “Enabled: Yes”.
You can also check in the app/etc/config.php
file.
Congratulations! You have successfully created a basic Magento 2 module. Now you can proceed with adding more functionality to this module, such as controllers, models, blocks, and templates, depending according to your requirements.
Remember to run the necessary setup and upgrade commands to enable the module:
php bin/magento setup:upgrade
php bin/magento cache:flush
For more - Adobe official
Thank you for reading my Article! Feel free to share your thoughts or ask any questions in the comments section below and spread the word by sharing. Your engagement is appreciated!
2 thoughts on “How to Create Basic Module in Magento 2”