Hyvä Theme is Now Open Source: What This Means for Magento Community - Mageplaza
Hyvä is now Open Source and free. Discover what changed, what remains commercial, how it impacts the Magento ecosystem, and how to maximize its full potential.
Vinh Jacker | 03-17-2025
According to eMarketer’s projections, retail ecommerce sales are anticipated to escalate from $4.938 trillion in 2021 to $7.391 trillion by 2025. To capitalize on this growth, learning to develop a custom module in Magento 2 can significantly boost sales by adding unique functionalities to your online store.
In this guide, we will outline five essential steps to create a custom module in Magento 2. Let’s explore!
Looking for a Trusted Magento Development Company?
137,000 clients can’t be wrong! Ready to become our next success story?
Our Magento experts are willing to help you with any tasks!
Get FREE 1:1 ConsultationA custom module in Magento 2 is a package of code designed to add specific features or functionalities to an online store. It allows developers to extend, customize, or modify Magento’s default behavior without altering the core code. Custom modules can introduce new product types, payment gateways, shipping methods, or other features tailored to meet unique business needs, ensuring a flexible and scalable e-commerce platform.
To create custom modules, you need to complete the following high-level steps:
Name of the module is defined as VendorName_ModuleName. First part is name of the vendor and last part is name of the module:
For example: Magento_HelloWorld, Mageplaza_PdfInvoice. Focus on following guide to create the folders:
app/code/Mageplaza/HelloWorld
Then, it is necessary to create etc folder and add the module.xml file
app/code/Mageplaza/HelloWorld/etc/module.xml
Contents would be:
<?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="Mageplaza_HelloWorld" setup_version="1.0.0">
</module>
</config>
In this step, we will add registration.php as following guide:
app/code/Mageplaza/HelloWorld/registration.php
Contents would be:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Mageplaza_HelloWorld',
__DIR__
);
Finish the step 3, we have already created the HelloWorld module. And we will enable this module in this step
After create the module if you run the command as:
php bin/magento module:status
You should see the module is disable now:
List of disabled modules:
Mageplaza_HelloWorld
Follow exact guide to enable the module right now, let run the command as:
php bin/magento module:enable Mageplaza_HelloWorld
Or other way, you can access the file:
app/etc/config.php
You will see a long list of modules there, just add your module as well
...
'Mageplaza_HelloWorld' => 1,
...
Your module should be available now.
After this step, when you open your website in browser you will get an error saying
Please upgrade your database: Run bin/magento setup:upgrade from the Magento root directory.
Let run the command:
php bin/magento setup:upgrade
If you encounter issues with stuck indexers after enabling your module, you may need to unlock the reindex process in Magento 2 to continue development smoothly.
After complete,when you open your website in browser you will see the layout of the website is broken.

Please run the deloy command line to fix it.
php bin/magento setup:static-content:deploy
After deploy completed, you can also see your module from backend at System Configuration -> Advanced -> Disable Modules Output.
Now, we will create a controller to test module.
Before create a controller, we will create a route for HelloWorld module.
Route’s in magento are divided into 3 parts: Route frontname, controller and action as following example:
http://mageplaza.com/index.php/frontname/controller/action
To add route, it is necessary to create routes.xml file
app/code/Mageplaza/HelloWorld/etc/frontend/routes.xml
since this is a frontend route, we added it in frontend/ folder else we need to add it to adminhtml/ folder
Content would be:
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="helloworld" id="helloworld">
<module name="Mageplaza_HelloWorld"/>
</route>
</router>
</config>
After defining the first part of the route, the URL will be displayed as:
http://<yourhost.com>/helloworld/*
E.g: http://localhost/helloworld/*
Then, we will continue to create the controller and action
The folder and file you need to create is:
app/code/Mageplaza/HelloWorld/Controller/Index/Test.php
Contents would be:
<?php
namespace Mageplaza\HelloWorld\Controller\Index;
class Test extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}
public function execute()
{
echo "Hello World";
exit;
}
}
After completed, please run php bin/magento cache:clean to check result.
Your URL now should be as:
http://<yourhost.com>/helloworld/index/test

We hope that the above easy-to-understand guide will help you successfully create a custom module in Magento 2.
Need help building something more advanced? Explore our Custom Magento Development Services and bring your ideas to life with expert support.
1. What is module.xml in Magento?
module.xml is a configuration file in Magento that defines the specifics of a Magento module. This file provides crucial information such as the module’s name, version, and dependencies. Magento modules follow a structured folder hierarchy, which includes the vendor (a collection of related modules) and the module itself. The module.xml file, located within this structure, helps Magento identify the module’s properties and requirements, ensuring proper integration and functionality within the Magento framework.
2. How can you call ( activate) a module in Magento 2?
To activate a module in Magento 2:
app/code/VendorName/ModuleName.php bin/magento module:enable VendorName_ModuleName.setup:upgrade.php bin/magento cache:clean and php bin/magento cache:flush.Following these steps will activate your module in Magento 2, making it operational within the system.
3. Can I create multiple modules within the same Magento 2 instance?
Yes, Magento 2 allows you to create and manage multiple modules within the same Magento 2 instance. Modules in Magento are like building blocks that allow you to extend or modify the core system’s functionality.
4. Where are Magento modules stored?
Magento modules are stored in the app/code directory of your Magento installation. Specifically, they are organized into vendor-specific folders within app/code. For example, if the vendor name is VendorName and the module name is ModuleName, the module’s files are located in app/code/VendorName/ModuleName. This directory structure helps Magento manage and organize modules according to their respective vendors and names, facilitating easy customization and extension of the platform’s functionalities.
5. Is it possible to create a module that integrates with third-party APIs?
Yes, it is possible to create a module in Magento 2 that integrates with third-party APIs. Magento 2 provides robust capabilities for developers to build custom modules that interact with external APIs seamlessly. Learn how to expose your module via Magento 2 API if you want your module to expose endpoints and interact via RESTful requests. Here are the general steps:
app/code/VendorName/ModuleName.module.xml and registration.php) and define dependencies.