How to create a basic extension in Magento 2

How to create a basic extension in Magento 2

/ Magento 2 / extension, admin / 0

In this tutorial, we will build a basic extension for Magento 2. This extension will not work on its own. However it is the first step in the construction of any extension for Magento 2 of any type, and it is a mandatory step as well.


Before we start, there's an important step that we need to do:

Disable Magento cache

The easiest way to turn off the cache is to go to your Magento admin panel → System → Cache Management → At Mass Action choose "Select All" → At Actions choose "Disable" instead of "Refresh" → Now click on "Submit".

At this point all your caches must show "DISABLED" status like in my screenshot:

Now that we have disabled the cache, we can continue by creating the folder structure and the mandatory files that Magento requires in order to recognize your extension.


1. Create the following structure

You must note that if you are working with a fresh install, you will also need to create the folder app/code/ because this is not created by default.

  • app/code/<Vendor>
  • app/code/<Vendor>/<Extension>
  • app/code/<Vendor>/<Extension>/etc

In this example I will create an extension for testimonials, so for <Vendor> I will use DEVLINE and Testimonial for <Extension>, so I will have the following folder structure:

  • app/code/DEVLINE
  • app/code/DEVLINE/Testimonial
  • app/code/DEVLINE/Testimonial/etc


2. Now let's register our module by creating a registration.php in the folder app/code/DEVLINE/Testimonial/ and adding the following content:




3. The last step is to name and declare our module by creating a module.xml in the folder app/code/DEVLINE/Testimonial/etc and adding the following content:

<?xml version="1.0"?>
<config xmlns:xsi=""
    <module name="DEVLINE_Testimonial" setup_version="1.0.0"/>
  • name = name of your module
  • setup_version = database schema version

Both attributes of the <module> tag are required, even if you do not have a database schema.


At this point, you have all the necessary files for a Magento 2 extension. All you need to do is to run the next command in your terminal:

php bin/magento setup:upgrade

If this ran successfully, you would be able to see your extension in your admin panel already.

To check this you have to go to Magento admin panel → Stores → Configuration → Advanced → Advanced and search for your extension in the list. You need to see yours like in my screenshot:

You have successfully created a basic extension for Magento 2. This extension does nothing, but at the same time, it is necessary for creating admin grid, blocks, controllers and models.

P.S.: Do not forget to enable your cache :)


No comments