Magento 2 Module Development - Simple Hello World Module

Magento 2 Module development or Magento 2 Hello World trends is increase rapidly while Magento release official version. That why we - Mageplaza - are wring about a topic that introduces how to create a simple Magento 2 Simple Module.

As you know, the module is a directory that contains blocks, controllers, models, helper, etc - that are related to a specific business feature. In Magento 2, modules will be live in app/code directory of a Magento installation, with this format: app/code/<Vendor>/<ModuleName>. Now we will follow this steps to create a simple module which work on Magento 2 and display Hello World.

Basic Topics

Create Hello World module for Magento 2

To create Hello World module, you need to complete the following high-level steps:

  • Step 1: Create the folder of Hello World module
  • Step 2: Create etc/module.xml file
  • Step 3: Create etc/registration.php file
  • Step 4: Enable the module

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


Step 2: Create etc/module.xml file.

Then, it is necessary to create etc folder and 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_HelloWorld" setup_version="1.0.0">

Step 3: Create etc/registration.php file

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 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:


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

After complete,when you open your website in browser you will see the layout of the website is broken.

magento 2 broken upgrade

Please run

php bin/magento setup:static-content:deploy

to fix this.

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:

To add route, it is necessary to create 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="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route frontName="helloworld" id="helloworld">
            <module name="Mageplaza_HelloWorld"/>

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


Then, We will continue the controller and action

The folder and file you need to create is:


Contents would be:

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";

After completed, please run php bin/magento cache:clean to check result.

Your URL now should be as:


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.

Create Controller

Enjoyed the tutorial? Spread it to your friends!

Comments for Magento 2 Module Development - Simple Hello World Module

Please leave comments if you have any questions, feedbacks.

Module Development

You also may like these Magento 2 Extensions

One Step Checkout

10 reviews

Layered Navigation

12 reviews


no review

People also searched for:

  • Magento 2 Module Development
  • magento 2 simple module
  • magento 2 hello world
  • create module in magento 2
  • magento 2 create extension
  • magento 2 custom module
  • magento 2 extension tutorial
  • magento 2 module creation
  • magento 2 create simple module
  • magento 2 module tutorial
  • magento 2 create module
  • magento 2 create custom module
  • how to create module in magento 2
  • create magento 2 module
  • create module magento 2
  • magento 2 module development
  • magento2 create module
  • Magento 2 hello world
  • magento 2 extension development
  • magento 2 tutorial for beginners step by step
  • magento 2 tutorial for developer