Step 1. Disable Magento cache (recommended)

Disabling Magento cache during development will save you some time because you won’t need to manually flush the cache every time you make changes to your code.

The easiest way to disable cache is to go to Admin ? System ? Cache Management ? select all cache types and disable them.

Step 2. Put Magento into a developer mode (recommended)

You should put Magento into a developer mode to ensure that you see all the errors Magento is throwing at you.

In order to do this, open your terminal and go to the Magento 2 root. From there you should run the following command:

php bin/magento deploy:mode:set developer

Step 3. 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.

Focus on following guide to create the folders:


Step 4. 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="NS_Firstmodule" setup_version="0.0.1"/>


Step 5. Create etc/registration.php file

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


Contents would be:


Step 6. Enable the module

Finish the step 5, we have already created Firstmodule the module. And we will enable this module in this step

After create the module run the next commands:

php bin/magento setup:upgrade

If all is good, you will see you module in list, for example:

for example

php bin/magento setup:static-content:deploy

Step 7. Creating a controller

  •  First we need to define the router.

To do this, create a routes.xml file in the


folder with the following code:

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
   <router id="standard">
       <route id="firstmodule" frontName="firstmodule">
           <module name="NS_Firstmodule" />

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


  • Create controller

The folder and file you need to create is:


Contents would be:

namespace NS\Firstmodule\Controller\Index;
class HelloWorld extends \Magento\Framework\App\Action\Action{
   public function execute()
       echo "Hello! It’s my first module of Magento 2!";

After completed, please run sudo bin/magento cache:flush
to check result.

Your URL now should be as:


After finish all steps, the output Hello! It’s my first module of Magento 2! should be displayed in your browser when you open the URL.


5.00 / 5.0
Article rating (7 Reviews)
Do you find this article useful? Please, let us know your opinion and rate the post!
Not badGoodVery GoodGreatAwesome