{"id":1319,"date":"2020-10-27T05:53:36","date_gmt":"2020-10-27T05:53:36","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/10\/27\/create-module-in-magento-2\/"},"modified":"2025-03-17T13:13:10","modified_gmt":"2025-03-17T13:13:10","slug":"create-module-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/create-module-in-magento-2\/","title":{"rendered":"How to Create Module in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/what-is-magento\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2<\/a>&nbsp;CMS is an excellent option to develop an online store. However, it&nbsp;may not be enough for modern business requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To overcome the default limitations, there are&nbsp;<a href=\"https:\/\/meetanshi.com\/magento-2-extensions.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 extensions<\/a>&nbsp;available in the market that extend the functionality of Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also opt to&nbsp;<em><strong>create module in Magento 2<\/strong><\/em>&nbsp;rather than approaching any third party extension providers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, you may have tons of questions regarding&nbsp;<strong>Magento 2 module development&nbsp;<\/strong>such as how one can develop Magento 2 module that helps the Magento 2 store to increase store facility, what are the most important things for the development of a module and so on.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Well, don\u2019t worry.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here we have prepared a comprehensive guide on creating your first Magento 2 module.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To create a module or extension in Magento 2, you need to create these important files.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>module.xml<\/li>\n\n\n\n<li>registration.php<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">But, before getting started, let\u2019s discuss some of the basic things that you need to know.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The extension is built under app\/code. When you go through this path, the first folder name demonstrates the name of the extension provider company. The second folder shows the name of the extension.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For easy explanation, we are here giving the name of extension \u201cExtension\u201d and the name of a company \u201cMeetanshi\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alright. So coming back to the important files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What you need to do is create a file having a specific path.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to create a module in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<em><strong>module.xml<\/strong><\/em>&nbsp;at&nbsp;<strong>a<em>pp\/code\/Meetanshi\/Extension\/etc&nbsp;<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In module.xml file, copy and paste this code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"..\/..\/..\/..\/..\/lib\/internal\/Magento\/Framework\/Module\/etc\/module.xsd\">\n    &lt;module name=\"Meetanshi_Extension\" setup_version=\"1.0.0\">\n    &lt;\/module>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you also need to create a file that is registration.php.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create&nbsp;<em><strong>registration.php<\/strong><\/em>&nbsp;at&nbsp;<strong><em>app\/code\/Meetanshi\/Extension<\/em><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nuse Magento\\Framework\\Component\\ComponentRegistrar;\nComponentRegistrar::register(\n    ComponentRegistrar::MODULE,\n    'Meetanshi_Extension',\n    __DIR__\n);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These two files are mandatory to create and get started with extension development.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2020\/10\/How-to-create-module-in-Magento-2.png\" alt=\"How to create module in Magento 2\" class=\"wp-image-11146\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">After creating module.xml and registration.php files, the next step is to execute commands in the command line.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php bin\/magento setup:upgrade\nphp bin\/magento setup:static-content:deploy -f\nphp bin\/magento cache:flush<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run these three commands and your extension will appear in&nbsp;<em><strong>app\/etc\/config.php<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the command gives output \u20180\u2019, that indicates the extension is disabled. On the other hand, if the command shows output \u20181\u2033, it explains that the extension is enabled and all the functionalities of the extension are working smoothly.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2020\/10\/Magento-2-Extension-Development-Guide-e1603694991941.jpg\" alt=\"Magento 2 Extension Development Guide\" class=\"wp-image-11091\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The image explains that the name of the extension \u201cMeetanshi_Extension\u201d is enabled.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the next tutorial, you will learn how to display a message on the frontend.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, if you do not want the hassle of creating an extension on your own, you can visit&nbsp;<a href=\"https:\/\/meetanshi.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Meetanshi<\/a>&nbsp;for top-notch extensions developed by&nbsp;<a href=\"https:\/\/www.credly.com\/badges\/7d09d31c-c136-4c65-8ed0-27e50cb7c77d\/public_url\" target=\"_blank\" rel=\"noreferrer noopener\">certified Magento developers<\/a>!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not forget to share the series of Magento 2 module development tutorials with the beginners via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The&nbsp;Magento 2&nbsp;CMS is an excellent option to develop an online store. However, it&nbsp;may not be enough for modern business requirements. To overcome the default limitations,&#8230;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1319","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1319"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1319\/revisions"}],"predecessor-version":[{"id":9915,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1319\/revisions\/9915"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}