To uninstall a Magento 2 extension you need to know how it was installed. An extension installed manually can be uninstalled by disabling the extensionand removing the extension files. An extension installed using Composer can be uninstalled by disabling the module and removing via Composer.
Let’s take a closer look at the exact steps involved in uninstalling Magento extensions using both methods.
Note: Always backup your files and database to prevent data loss if the uninstallation process fails. While this tutorial describes the standard procedure of uninstalling an extension, some extensions may require additional steps. You should checkextension`s manual for any additional steps required to complete the uninstallation.
Uninstalling a manually installed extension
Step 1: Enable maintenance mode
Connect via SSH to the your Magento store and navigate to the Magento root directory. Enable maintenance mode to restrict access to your website’s frontend by running the following command:
$ php bin/magento maintenance:enable
Step 2: Disable the extension and update dependencies
Next, check the status of the extension by running the following command:
$ php bin/magento module:status <VendorName>_<ComponentName>
You can also run this command without specifying the extension name, in which case you will be presented with a list of all extensions grouped by their status.
If your extension is enabled, run the following command to disable the extension and to clear static view files:
$ php bin/magento module:disable <VendorName>_<ComponentName> --clear-static-content
Next, update your Magento application by running the following command:
$ php bin/magento setup:upgrade
Additionally, you can also clear all caches by running the following command:
$ php bin/magento cache:flush
Step 3: Remove extension files
Finally, to complete the uninstallation, remove the extension directory and its contents by running the following command:
$ rm -rf <path-to-extension-folder>
Be careful when specifying the path to the extension folder, as deleting the wrong folder is irreversible. If you delete an incorrect folder, roll back the filesystem using the backup you may have created before starting the uninstallation.
Step 4: Verify uninstallation
To make sure that the uninstallation has been successfully completed, you can run the following command:
$ php bin/magento module:status <VendorName>_<ComponentName>
Alternatively, run the command without specifying the extension name and go through the list of all available extensions to confirm that the one you’ve uninstalled isn’t listed.
Step 5: Disable maintenance mode
After you’ve verified the uninstallation, disable maintenance mode and open your website in a web browser to confirm the frontend and admin panel are working as expected. To disable maintenance mode, run the following command:
$ php bin/magento maintenance:disable
Congratulations, you have successfully uninstalled your extension using the manual method.
Uninstall an extension installed using Composer
Step 1: Enable maintenance mode
Start by enabling maintenance mode to restrict access to your website’s frontend by running the following command as the Magento filesystem owner inside the root directory of your Magento installation:
$ php bin/magento maintenance:enable
Step 2: Uninstall the extension
Next, disable the extension and clear previously generate static view files by running the following command:
$ php bin/magento module:disable <VendorName>_<ComponentName> --clear-static-content
Once the extension has been disabled, run the following commands to uninstall the extension using Composer and update dependencies:
$ composer remove <vendor-name>/<module-name> $ php bin/magento setup:upgrade
Replace '<vendor-name>/<module-name>' with that of your extension. You can find your '<vendor-name>/<module-name>' in composer.json file associated with the extension.
Optionally, you can also clear your Magento cache by running the following command:
$ bin/magento cache:flush
Step 3: Verify uninstallation
Verify the uninstallation has been successfully completed by running the following command:
bin/magento module:status <VendorName>_<ComponentName>
Step 4: Disable maintenance mode
Next, disable maintenance mode by running the following command:
$ bin/magento maintenance:disable
Finally, open a web browser and verify that your website and admin panel are working as expected. If you notice any errors at this stage, go back to the command line and run the following command:
$ php bin/magento cache:flush
Congratulations, you have successfully uninstalled your extension using Composer.