Plainsurf Solutions

Magento 2 Basic Commands And Module Management

Introduction :-

Welcome to the comprehensive guide on Magento 2 Module Management. Learn how to effortlessly enable, disable, install, and uninstall modules while configuring them to suit your needs. Discover the power of cache management and DI compile to boost your store’s performance. Get ready to unleash the full potential of your Magento 2 installation with this insightful tutorial.

Module Management :-

In Magento 2, module management refers to the process of enabling, disabling, installing, uninstalling, and configuring modules within your Magento installation.

1} Module Structure :-

The module files are typically located in the app/code directory.
The module’s code resides in the app/code/VendorName/ModuleName directory, where VendorName represents the name of the module’s creator and ModuleName represents the name of the modu

2} Enable a Module :-

command :- bin/magento module:enable VendorName_ModuleName
ex :- bin/magento module:enable Example_Module

After enabling the module, run setup upgrade command :-

bin/magento setup:upgrade

Running “setup upgrade” after enabling a module is necessary to apply database changes and configuration updates required for the new module’s functionality to work correctly.

3} Disable a Module :-

command :- bin/magento module:disable VendorName_ModuleName
ex :- bin/magento module:disable Example_Module

After disable the module, run setup upgrade command :-

bin/magento setup:upgrade

Running “setup upgrade” after disabling a module is necessary to roll back any database changes and configuration updates made by the module, restoring the application to its previous state before the module was enabled.

4} Install a Module :-

  • Download or Install the Module:
  • Extract or Install the Module:
  • Copy the Module Files and paste to app/code/Example/Module directory
  • Run Setup Commands :-
bin/magento setup:upgrade
bin/magento setup:di:compile 
bin/magento cache:flush

OR :-

 composer config type path
EX :- composer config git
composer require vendorname/modulename:type-ofbranch

Then run setup , di and cache flush commands.

5} Uninstall a Module :-

command :- bin/magento module:uninstall VendorName_ModuleName
ex :- bin/magento module:uninstall Example_Module

After uninstall the module, run setup upgrade command :-

bin/magento setup:upgrade

Running “setup upgrade” after uninstalling a module is necessary to remove any residual database changes and configurations made by the module, ensuring the application is in a clean and consistent state without the module’s impact.

6} View Module Status :-

command :- bin/magento module:status

It provides all installed modules and their status (enabled or disabled).

7} Configure a Module :-

Modules in Magento 2 often come with their own configuration settings. You can configure module settings by navigating to Stores -> Configuration in the Magento Admin panel

after enabling, disabling, installing, or uninstalling a module, running the bin/magento setup:upgrade command is necessary to apply any database changes or system configuration updates.


command is used to upgrade the Magento application and its modules. It performs necessary database schema changes, data migration, and module version upgrades

bin/magento setup:upgrade

used for :-

1} Database Schema Changes

2} Data Migration :-

if a module has data migration scripts then setup:upgrade executes these scripts to migrate data from previous module versions to the new version. Data migration scripts handle the transformation and transfer of data during module upgrades.

3} Module Version Upgrades :-
4} Applying Module Configuration Changes

after setup:upgrade command run you need to run chache:flush command this command ensures any cached data to reflace the changes made during upgrade

setup:deploy :-

setup:deploy command is used to deploy static view files, such as CSS, JavaScript, and images, from modules and themes to the Magento pub/static directory.

All view files are located in app/code app/design and vendor directories of modules and themes
setup:deploy command collects these static view files and deploys them to the Magento pub/static directory.

During the deployment process, Magento can perform file minification and merging to optimize the loading speed of static files. This reduces the number of HTTP requests and improves frontend performance.

bin/magento setup:deploy

why we use :-

1} Prepare for Production

2} New Module Installation: When you install a new module that includes static view files, running setup:deploy deploys those files to the pub/static directory. This allows the module’s frontend assets to be accessible and used by the store.

3} Theme Changes or Installation: If you make changes to a theme or install a new theme, running setup:deploy ensures that the updated or new theme’s static files are deployed and available for the storefront.
This command starts the deployment process and deploys the static view files from modules and themes to the pub/static directory.
After the deployment process completes, you may need to clear the cache

cache management :-

Why cache management is important :-

1} Improved Performance:

2} Reduced Server Load:

3} Scalability

when and how use cache managemnt:-

when :-
1} After Configuration Changes:
2} After Content Updates
3} After Module Installation/Upgrade:
4} Debugging and Development

How :-

1} Check current status :-

bin/magento cache:status

2} to flush enabled cache :-

bin/magento cache:flush

3} to clean but not flush :-

bin/magento cache:clean

4} To enable or disable specific cache types :-

bin/magento cache:enable
bin/magento cache:disable

DI Compile :-

DI (Dependency Injection) compile is a process that generates the DI configuration files and compiles them into a single file. It is used to improve the performance of the Magento 2 application by reducing the overhead of dependency injection during runtime.

Why and when to use DI compile :-

1} After Module Installation/Upgrade:
2} After Configuration Changes

How to use DI compile :-

bin/magento setup:di:compile

what dose it :- This command triggers the compilation process and generates the DI configuration files.

It’s important to note that after running DI compile, you need to flush the cache to ensure that the changes take effect.

Check our blogs :-

1} Troubleshooting Guide: How to Solve Login Issues in Magento 2 for your localhost :-

2} Creating a VPC in AWS: Simplified Setup for Secure Networking

Official website of Magento2 :-