How to Create Module in Magento 2 - Helloworld development series - Completed Guide


We will discuss the topic of how to create Hello World module in Magento 2 in order to help you have the clearest and easiest way to create now. Remember that the concept of local/ community/ core/ folders only existed in Magento 1 and you will don’t use them for Magento 2.

To create Hello World module in Magento 2:

Step 1: Create the folder of Hello World module

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_Helloworld. Focus on following guide to create the folders:


Step2: Add module.xml

Then, it is necessary to add the module.xml file


Contents would be:

  <?xml version="1.0"?>
  <config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
  <module name="Mageplaza_Hello" setup_version="0.0.1"/>

Step3: Add registration.php

In this step, we will add registration.php as following guide:


Contents would be:


Step 4: Enable the module

Finish the step 3, we have already created the Hello World 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_Hello

Follow exact guide to enable the module right now, let run the command as:

  php bin/magento module:enable Mageplaza_Hello

Or other way, you can access the file:


You will see a long list of modules there, just add your module as well

  'Mageplaza_Hello' => 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:

  bin/magento setup:upgrade

to fix the error. You can also see your module at System Configuration -> Advanced -> Disable Modules Output

Step5: Create a Routes for the module

In this step, you should add an url known as a route so that you can display Hello World

Route’s in magento are divided into 3 parts: Route_id, controller and action as following example:

To add route, it is necessary to add routes.xml file


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="" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="standard">
        <route id="mageplaza" frontName="mageplaza">
            <module name="Mageplaza_Hello" />

You should define ID and FrontName is the same because some mistakes maybe occur during your setup processing.

After define the first part of the route, the URL will be displayed as:*

Then, you will continue define our controller, action

Your URL now should be as:

The folder you need to create is:


That folder should contain the following content:

  namespace Mageplaza\Hello\Controller\Hello;
  class World extends \Magento\Framework\App\Action\Action
    public function __construct(
        \Magento\Framework\App\Action\Context $context)
        return parent::__construct($context);
    public function execute()
        echo 'Hello World';

After finish all steps, the output “Hello World” should be displayed in your browser when you open the URL. We hope our guide is very useful and effective for you.

Please leave comments if you have any questions, feedbacks.

Comments for How to Create Module in Magento 2 - Helloworld development series - Completed Guide

You also may like these Magento 2 Extensions

One Step Checkout

13 reviews

Layered Navigation

5 reviews


5 reviews


7 reviews


10 reviews

Store Locator

no review

Shop By Brand

no review

Better Blog

7 reviews