In this blog we will create our first module with name “BlogManager”.
Before diving into developing, let’s set the mode to Developer so that we can see errors if occur, on the browser itself. To set the mode we have to run the command php bin/magento deploy:mode:set developer
from the magento root directory (the directory where magento is installed). There are three modes in Magento 2, (i) Developer, (ii) Default and (iii) Production.
To create module the module we have to create vendor folder with vendor name (which is Webkul in our case) under app/code folder (if code folder is not available then please create it). Then we have to create the module folder “BlogManager” (the module name).
First we have to register our module with registration.php so that magento can recognise it as a module. The registration.php will be under module folder and the content will be
Types of components are,
i) Module
ii) Theme
iii) Language
iv) Library
Now we need to create etc folder under the module directory and in the etc folder we need to create module.xml file with following content
Earlier (before Magento 2.4) we use to write module version in module tag like <module name="Webkul_BlogManager" setup_version="2.0.0">
After creating these two files we need to run the setup upgrade command like below. It will activate the module.
Folder structure should look like,
Note that we have to run all the magento commands from magento root directory as shown below,
P.S. To view all the errors we have to uncomment a line in app/bootstrap.php file,
Make sure the module is enabled as well