Magento 2 – Creating a Magento Module: A Beginner’s Guide
Magento's modular architecture empowers developers to customize and extend functionality. In this tutorial, we'll guide you through the essential steps to create a basic Magento module.
Here is our Magento module creation guide.
Step 1: Set Up Your Development Environment
Ensure you have a Magento instance for development. Familiarize yourself with Magento's file structure and basic module concepts.
If you need to set it up quickly check Mark Shust solution : https://github.com/markshust/docker-magento
Step 2: Create the Module Directory Structure
Navigate to the app/code
directory and create the directory structure for your module. For instance, if your module is named MyModule
, the path should be app/code/Vendor/MyModule
.
Step 3: Define Module Configuration
Inside your module directory, create a registration.php
file to register your module:
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Vendor_MyModule', __DIR__ );
Step 4: Create Module Configuration File
Create a module.xml
file in app/code/Vendor/MyModule/etc
:
<?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="Vendor_MyModule" setup_version="1.0.0"/> </config>
Step 5: Enable the Module
Run the following command in the Magento root directory to enable your module:
php bin/magento module:enable Vendor_MyModule
Step 6: Verify Your Module
Check the enabled modules by running:
php bin/magento module:status
Your module, Vendor_MyModule
, should appear in the list.
Congratulations! You've created a minimal Magento module using our Magento module creation guide. While this module doesn't include a custom controller, you can build upon this foundation to add more features and functionality as needed. Happy coding!