Create a Simple Magento 2 Module

Create a HelloWorld Module in magento 2

Steps of creating a simple magento 2 module.

Step 1: Create the directory of the module,

In this module, we will use Bluethink for Vendor name and HelloWorld for ModuleName. So we need to make this folder:


Step 2: Declare module by using configuration file module.xml

We need to create folder etc and add module.xml:


and put this content in the module.xml

<?xml version=”1.0″?>
<config xmlns:xsi=”” xsi:noNamespaceSchemaLocation=”urn:magento:framework:Module/etc/module.xsd”>
<module name=”Bluethink_HelloWorld” setup_version=”1.0.0″ />

Step 3: Register module by registration.php

We need to create a file named registration.php in HelloWorld directory.


and put this content in the registration.php

Step 4: Check status of module

For checking the status of module run the following command:

php bin/magento module:status

If you follow above step, you will see this in the result:

List of disabled modules:

Step 5: This means the module has recognized by the system but it is still disabled. Run this command to enable it:

php bin/magento module:enable Bluethink_HelloWorld

The module has enabled successfully if you saw this result:

The following modules has been enabled:
– Bluethink_HelloWorld

This’s the first time you enable this module so Magento require to check and upgrade module database. We need to run this comment:

php bin/magento setup:upgrade

Now you can check under Stores -> Configuration -> Advanced -> Advanced that the module is present.

Step 6: Create a Routers for the module.


The Router is used to assign a URL to a corresponding controller and action. In this module, we need to create a route for frontend area. So we need to add this file:


And content for this file:

<?xml version=”1.0″?>
<config xmlns:xsi=”” xsi:noNamespaceSchemaLocation=”urn:magento:framework:App/etc/routes.xsd”>
<router id=”standard”>
<route id=”Bluethink” frontName=”helloworld”>
<module name=”Bluethink_HelloWorld” />

After define the route, the URL path to our module will be:

Step 7: Create Controller and Action

In this step, we will create controller and action to display Hello World. Now we will choose the url for this action. Let assume that the url will be:

So the file we need to create is:


And we will put this content:

namespace Bluethink\HelloWorld\Controller\Index;

class Display 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’;

If you have followed all above steps, you will see Hello World when open the url