Table of contents
Magento 2 allows you to enable or disable currently available modules; in other words, any Magento-provided module or any third-party module that is currently available.
How to enable or disable modules
Enabling or disabling modules in Magento 2 is as simple as executing a command from your Magento root, or editing the config.php file.
By using CLI
Step 1: Log in to Magento server
Log in to the Magento server as, or switch to, a user who has permissions to the Magento file system. One way to do this is to switch to the Magento file system owner.
If you use the bash shell, you can also use the following syntax to switch to the Magento file system owner and enter the command:
su <Magento file system owner> -s /bin/bash -c <command>
If the Magento file system owner does not allow logins you can do the following:
sudo -u <Magento file system owner> <command>
Step 2: Execute commands to enable or disable modules
If you haven’t got the exact name of your module, use the following command to list all modules:
php bin/magento module:status
To enable or disable available modules, use the following command from your Magento root:
magento module:enable [-c|--clear-static-content] [-f|--force] [--all] <module-list> magento module:disable [-c|--clear-static-content] [-f|--force] [--all] <module-list>
where
<module-list>
is a space-delimited list of modules to enable or disable. If any module name contains special characters, enclose the name in either single or double quotes.--all
to enable or disable all modules at the same time.-f
or--force
to force a module to be enabled or disabled despite dependencies.-c
or--clear-static-content
cleans generated static view files. Because of static file fallback rules, if you do not clear static files and there is more than one file named logo.gif that are different, fallback might cause the wrong file to display.
For example, after a fresh install of Magento 2, you might run into the two-factor authentication issue like so when trying to log into your Magento Admin:
This is caused by unconfigured Two-Factor Authorization. To get around this, you’ll want to disable the Magento_TwoFactorAuth
module by executing the following command:
php bin/magento module:disable Magento_TwoFactorAuth
Step 3: Update the database
If you enabled one or more modules, run the following command to update the database schema:
php bin/magento setup:upgrade
By editing /app/etc/config.php
Alternatively, you could also edit config.php
in <your_Magento_root>/app/etc/
in order to disable or enable modules. Opening this file should give you a list of modules as follow:
<?php return [ 'modules' => [ 'Magento_AdminAnalytics' => 1, 'Magento_Store' => 1, 'Magento_AdobeIms' => 1, 'Magento_AdobeImsApi' => 1, 'Magento_AdobeStockAdminUi' => 1, 'Magento_MediaGallery' => 1, 'Magento_AdobeStockAssetApi' => 1, 'Magento_AdobeStockClient' => 1, 'Magento_AdobeStockClientApi' => 1, 'Magento_AdobeStockImage' => 1, 'Magento_Directory' => 1, 'Magento_AdobeStockImageApi' => 1, 'Magento_AdvancedPricingImportExport' => 1, 'Magento_Theme' => 1, 'Magento_Amqp' => 1, 'Magento_AmqpStore' => 1, 'Magento_Config' => 1, 'Magento_Backend' => 1, 'Magento_Authorization' => 1, 'Magento_Eav' => 1, ] ];
To disable any module, simply change the value of your chosen value from 1
to 0
(and vice versa to enable any module). After you have finished configuring config.php
, update your database and clean the cache using:
php bin/magento setup:upgrade php bin/magento cache:clean
About module and dependencies
Certain modules have dependencies on other modules, in which case you might not be able to enable or disable a module because it has dependencies on other modules.
In addition, there might be conflicting modules that cannot both be enabled at the same time.
Examples:
- Module A depends on Module B. You cannot disable Module B unless you first disable Module A.
- Module A depends on Module B, both of which are disabled. You must enable module B before you can enable module A.
- Module A conflicts with Module B. You can disable Module A and Module B, or you can disable either module but you cannot enable Module A and Module B at the same time.
Dependencies are declared in the require field in Magento’s composer.json file for each module. Conflicts are declared in the conflict field in modules’ composer.json files. We use that information to build a dependency graph:
- A->B means module A depends on module B.
- A dependency chain is the path from a module to another one. For example, if module A depends on module B and module B depends on module C, then the dependency chain is A->B->C.
If you attempt to enable or disable a module that depends on other modules, the dependency graph displays in the error message.