Building a custom module is a great way to extend your Magento store, and getting started is easier when you understand how registration and configuration work. Magento 2 module registration configuration tells Magento that your module exists and how it should be loaded alongside the rest of the application.
In this guide, we’ll walk through the essential files and steps, from registering a module to setting up its basic configuration. Whether you’re creating your first module or refreshing your Magento skills, you’ll find a clear starting point for building with confidence.
Understanding Magento 2 module registration configuration
A Magento store is made up of many components working together, and a custom module needs a clear identity before it can join them. Knowing how Magento recognizes that identity makes the registration files—and the structure around them—much easier to understand.
First, let’s look at what a module represents and how Magento discovers one in a codebase.
What a Magento 2 module is and how Magento finds it
A module is a self-contained package of functionality that can add or change features in a Magento application. It might introduce a payment option, add an admin page, or provide a small integration. Modules can be developed in a project’s app/code directory or installed as Composer packages.
Magento uses component registration to recognize modules and other components. Once registered, a module can be included in the application’s configuration and setup processes. This is why placing files in a folder alone is not enough: Magento also needs the module’s name and registration details.
Two files work together to provide those details: one registers the component with Magento, while the other declares its module identity and any load-order relationships.
The roles of registration.php and etc/module.xml
In a typical custom module, registration.php sits in the module’s root directory. It calls Magento’s ComponentRegistrar to register the module name and its directory path, allowing Magento to locate the component’s files.
The etc/module.xml file declares the same module name in XML. It can also include a <sequence> element when the module should load after another module—for example, when it relies on that module’s configuration or functionality. A sequence establishes ordering; it does not replace proper dependency management.
With the files’ jobs clear, the naming convention and directory layout are easier to check at a glance.
A quick look at module naming and folder structure
Magento module names commonly use the format VendorModule. The vendor portion identifies the developer or organization, and the module portion describes the component. Keep the spelling and capitalization consistent in both registration files.
For a module named AcmeCatalogNote, a basic layout might look like this:
app/code/Acme/CatalogNote/registration.phpapp/code/Acme/CatalogNote/etc/module.xml
The folder path reflects the vendor and module names, while the module’s internal directories—such as etc, Controller, or Model—hold specific parts of its implementation. Consistent naming across the path and files helps avoid registration errors and gives Magento a reliable way to identify the module.
Create and register your first Magento 2 module
The files are ready to take shape—now it’s time to connect them to a working module. A quick, practical setup will show how Magento 2 module registration configuration moves from a directory on disk to an enabled component.
Start with the module’s location and registration call; these give Magento a path to follow when it scans the codebase.
Set up the module directory and registration file
Create app/code/Acme/CatalogNote, then add a registration.php file at its root. The vendor and module names in the directory should match the module name used in the code.
Add this PHP code to register the component:
<?php
use MagentoFrameworkComponentComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'AcmeCatalogNote',
DIR
);The DIR value points to the current module directory, so Magento can locate its files without a hard-coded path.
Next, declare the module in XML. This is also where you can specify load order when your code depends on another module.
Declare the module and its sequence in etc/module.xml
Create an etc directory inside Acme/CatalogNote, then add module.xml. Its declared name must exactly match the name in registration.php.
For example, if the module uses Catalog functionality, its XML can include this sequence:
<?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="AcmeCatalogNote">
<sequence>
<module name="MagentoCatalog"/>
</sequence>
</module>
</config>Include a sequence only when there is a real load-order dependency. It helps Magento merge configuration in the intended order, but it does not install or enable the named dependency.
With both declarations in place, use the command-line tools to enable the module and update Magento’s module list.
Enable the module and run the required CLI commands
From the Magento project root, enable the module and run the setup upgrade command:
bin/magento module:enable AcmeCatalogNote
bin/magento setup:upgrademodule:enable marks the component as enabled, while setup:upgrade applies module changes to the application. Run commands as the appropriate Magento filesystem owner; your environment may require a PHP version or command prefix.
Finally, check Magento’s reported status rather than relying only on the presence of the files.
Confirm the module is active
Run bin/magento module:status AcmeCatalogNote. Magento should list the module as enabled. If it does not, check the module name’s spelling and capitalization in both files, confirm the directory is under app/code, and rerun the enable and setup commands.
You can also inspect app/etc/config.php for an entry showing 'AcmeCatalogNote' => 1. Once active, the module is registered and ready for you to add its own configuration and functionality.
Configure and troubleshoot your module
Registration gets your component into Magento’s lineup; configuration determines how it behaves once it is there. With the module enabled, you can now add defaults, define how services are created, and check that the application picks up your changes.
It helps to distinguish the files that identify a module from those that shape its runtime behavior. This section connects those pieces and offers a practical way to diagnose common setup issues.
Where Magento 2 module registration configuration fits into setup
The files you created establish the module’s identity, while other configuration files extend Magento’s merged application configuration. Knowing that difference helps you choose the right place for each setting instead of adding unrelated instructions to module.xml.
For example, etc/config.xml can provide default values for settings defined by your module. These defaults are used when a store or administrator has not supplied a more specific value. By contrast, etc/di.xml describes dependency injection: how Magento should construct objects and which implementations to use.
Keep each file focused on its role. Registration and module declaration make the component discoverable; configuration files contribute settings or object relationships as Magento loads the application.
Add default settings and dependency injection configuration
When a feature needs a starting value, put it in the appropriate configuration file rather than hard-coding it into a class. The example below shows the general shape of a module’s default configuration; the exact path depends on the setting your feature reads.
etc/config.xml values can be overridden at the relevant store scope, so treat them as fallback values—not as a substitute for an administrator-facing settings page. For services, use etc/di.xml to declare constructor arguments or preferences only when necessary; a broad preference can affect other parts of the application.
After changing dependency injection declarations, run bin/magento setup:di:compile in production workflows, and clear or refresh relevant caches so Magento uses the updated configuration.
Check your configuration and resolve common errors
If a setting or class does not behave as expected, check the file path and XML structure before changing application code. A small typo in a node name, module identifier, or schema declaration can prevent configuration from being read.
Useful checks include:
- Run
bin/magento module:status Acme_CatalogNoteto confirm the module is enabled. - Run
bin/magento setup:upgradeafter adding or changing module setup information. - Review Magento logs and exception reports for XML validation or dependency-injection errors.
- Check file and directory permissions if Magento cannot read the module files.
When configuration changes seem invisible, refresh the relevant cache and verify that the setting is being read at the intended scope.
Follow best practices as your module grows
A small module is easier to maintain when its configuration stays deliberate. Use clear names, keep defaults conservative, and declare a sequence only for a genuine load-order requirement.
As features expand, separate admin-editable settings from internal defaults, avoid unnecessary global preferences, and test changes in a development environment before deployment. These habits keep your Magento 2 module registration configuration predictable and make future troubleshooting much simpler.
Build on a clear, reliable Magento module foundation
Getting a Magento 2 module up and running starts with giving it a consistent identity and making sure Magento can discover and enable it. From there, focused configuration helps your module work smoothly alongside the rest of the store.
Keep registration, defaults, and dependency injection in their proper roles, and verify changes with Magento’s CLI tools, logs, and cache refreshes. These habits make issues easier to spot and your Magento 2 module registration configuration easier to maintain as features grow.
With the essentials in place, you’re ready to move beyond setup and start building useful functionality—one well-structured module at a time.