How to remove Magento 2 extension

Unlike Magento 1, where removing extension requires only removing module files and special config XML file at app/etc/modules directory, Magento 2 yields a more complex way to remove the extension.

It ensures, that system will keep its stability even in cases of complex uninstall with dependencies.

There are two ways to remove the extension.

Removing with Composer (simple)

The best and safest way to remove extension is by using Composer. However, there´s simpler composer removal, and complex.

Pick Your Extensions

Free Installation

Free Support

Simple removal is best for simple extensions, that have no dependencies or connections with other extensions. Here is what you need to do:

  1. Log In via SSH/CLI to your domain and navigate to the root of your store.
  2. Run command bin/magento module:status. It will give you a list of enabled modules, where you can pick up an internal name of module you wish to remove. Let it be Mirasvit_Demo for our example.
  3. Run command bin/magento module:disable <Internal Module Name>. In our example it would be bin/magento module:disable Mirasvit_Demo. It will disable module.
  4. Run command bin/magento setup:upgrade. It will make Magento 2 remove it from all store activities.
  5. Navigate to the root directory of module you wish to remove. You will find there composer.json file. In our example it would locate at /vendor/mirasvit/module-demo/composer.json. In attribute name you will find your module composer name.

  6. Return to your store´s root and run command composer remove <composer name>. In our example it would be composer remove mirasvit/module-demo.

And this is all. The composer will remove all extension files smoothly.

But sometimes it is not enough, especially when the module has dependencies and heavily affects your store. In this case, you need to undertake a more complex approach.

Removing with Composer (complex)

Complex removal is recommended for modules with dependencies, or when module so much involved to your store, that removal needs maintenance mode. Luckily, Magento 2 automates this process and even has a special command for it. Here is what you need to do:

  1. Log In via SSH/CLI to your domain and navigate to the root of your store.
  2. Run command bin/magento module:status. It will give you a list of enabled modules, where you can pick up an internal name of module you wish to remove. Let it be Mirasvit_Demo for our example.
  3. Run command bin/magento module:uninstall [options] <internal module name>. In our case it would be bin/magento module:uninstall Magento_Demo
  4. If you wish to make Magento automatically backup your database, add option --backup-db. Tar-gzipped backup file will be placed to /var/backup directory.
  5. If you wish to make Magento automatically backup all store media (/pub/media directory), add option --backup-media. It will be also placed to /var/backup directory.
  6. If you wish to make Magento automatically backup store code (useful for restoring system after incorrect removal), add option --backup-code. It will backup your entire store, excluding temporary or generated directories. It will be also placed to /var/backup directory.
  7. If you need to automatically remove all tables, created by module, add option --remove-data.
  8. If you need to automatically clean static files after removal, add option --clear-static-content.
  9. For example, if we need to backup database and regenerate static contents, full command in our example would be bin/magento module:uninstall --backup-db --clear-static-content Magento_Demo

This command will stop, if it will find any dependencies, and show them to you.

bin/magento module:uninstall Mirasvit_Demo
Cannot uninstall module 'Magento_Demo' because the following module(s) depend on it:
Mirasvit_SampleData

In this case just prepend dependencies to your module name. So the command will look like this: bin/magento module:uninstall --backup-db --clear-static-content Magento_SampleData Magento_Demo

Command bin/magento module:uninstall then will automatically put your store to maintenance mode, disable and remove application, clean the cache and all data, that you had specified in options. After that it will run composer removal command and when it will complete, automatically take off maintenance state.

Manual Removal

If your store do not use composer, you can try to remove extension manually. Here is what you need to do:

  1. Log In via SSH/CLI to your domain and navigate to the root of your store.
  2. Run command bin/magento module:status. It will give you a list of enabled modules, where you can pick up an internal name of module you wish to remove. Let it be Mirasvit_Demo for our example.
  3. Run command bin/magento module:disable <Internal Module Name>. In our example it would be bin/magento module:disable Mirasvit_Demo. It will disable module.
  4. Run command bin/magento setup:upgrade. It will make Magento 2 remove it from all store activities.
  5. Run command rm -rf <Module Directory>.
  6. Clean the cache with bin/magento cache:clean and regenerate static contents with bin/magento setup:static-content:deploy -f commands.

This way, however, can result in unchecked errors, so we recommend to use composer for extension removal.

Did you know…

… that our latest extension, Stability Suite, can detect errors, connected with incorrect extension removal. It is extremely useful, when you do not use composer and undertake manual removals.

It also will offer you possibility to report you on the negative impact of changes made on your store performance indicators, slower loading speed, and so on.

Loading...