As your business grows, you’ll likely install Magento themes and extensions to improve your ecommerce store design and functionality. But when you add new modules, it’s also essential to remove old ones to avoid code conflicts and performance issues.
The steps to uninstall an extension in Magento 2 vary based on the installation process.
If the extension was installed using a Composer metapackage, you could uninstall it with the Magento module:uninstall command. However, if the extension was installed using an archive file, you must uninstall it manually.
In this tutorial, we’ll show you both methods to uninstall Magento 2 extensions.
Here’s what we’ll cover:
- Preconditions
- How To Uninstall an Extension in Magento 2
- How To Uninstall a Composer Extension in Magento 2
- Final Thoughts: How To Uninstall an Extension in Magento 2
Preconditions
No matter which method you use to uninstall extensions in Magento 2, follow these steps before you start:
Back Up Magento
Actions such as removing a Magento 2 theme or extension alter the Magento database and codebase. Creating a backup before making such changes ensures you can roll back to a functional version of your site if things go wrong.
Adobe deprecated the built-in Magento backup functionality in Magento versions 2.1.16, 2.2.7, 2.3.0, and above. Thus, we recommend consulting your hosting service provider to explore code and database backup options for your Magento store.
Nexcess customers can back up their Magento store by logging in to the Client Portal and initiating an on-demand backup from Plan Dashboard > Backups > Create Backup.
Change the Magento Operation Mode to Developer
Before turning on developer mode, clear all generated classes and proxies to prevent unexpected errors during the uninstallation process using:
<pre><code>
$ rm -rf <magento-root>/generated/metadata/* <magento-root>/generated/code/*
</code></pre>
Then, switch the Magento operation mode to developer using:
<pre><code>
$ php bin/magento deploy:mode:set developer
</code></pre>
How To Uninstall an Extension in Magento 2
1. Log in to your server and enable maintenance mode.
2. Disable the extension, update dependencies, and clear the Magento 2 cache.
3. Verify the uninstallation.
4. Remove the directory of module files from the “app” folder.
5. Disable maintenance mode.
Let’s explore the steps to uninstall an extension in Magento 2 manually.
1. Log In to Your Server and Enable Maintenance Mode
Log in to your Magento 2 server over SSH, navigate to the Magento root directory, and enable maintenance mode using:
<pre><code>
$ php bin/magento maintenance:enable
</code></pre>
2. Disable the Extension, Update Dependencies, and Clear the Magento 2 Cache
Disable the Magento 2 extension using the following command:
<pre><code>
$ php bin/magento module:disable <ExtensionProvider_ExtensionName> --clear-static-content
</code></pre>
For instance, here’s the command we’re using to disable our custom Magento 2 module:
<pre><code>
$ php bin/magento module:disable Nexcess_CustomModule --clear-static-content
</code></pre>
Once you’ve disabled the custom module, update the Magento project dependencies using the following command:
<pre><code>
$ php bin/magento setup:upgrade
</code></pre>
As an added measure, clear the Magento cache using the following command:
<pre><code>
$ php bin/magento cache:flush
</code></pre>
3. Verify the Uninstallation
You can verify if the extension uninstallation is successful using the following command:
<pre><code>
$ php bin/magento module:status <VendorName>_<ModuleName>
</code></pre>
The output should state “Module is disabled.”
4. Remove the Directory of Module Files From the “app” Folder
To complete the extension removal process, remove extension files from the Magento file system as follows:
<pre><code>
$ rm -R app/code/<extension-folder-name>
</code></pre>
5. Disable Maintenance Mode
Disable the maintenance mode using the command below:
<pre><code>
$ php bin/magento maintenance:disable
</code></pre>
Open your Magento storefront in a web browser and verify everything is working normally.
If you notice any issues, roll back to a previous version. Additionally, reach out to your third-party extension developer to help you uninstall the extension in Magento 2.
How To Uninstall a Composer Extension in Magento 2
If you install a Magento 2 module via Composer, you can remove it using either the “composer remove” command or Magento’s “module:uninstall” command.
It’s easier to uninstall Magento extensions using the uninstall script as it automates all the steps you would need with the “composer remove” command.
Here’s how you can uninstall an extension in Magento 2 using the module:uninstall command.
1. Log In to Your Server
Log in to your Magento server and navigate to the Magento installation folder via the command line interface. We don’t need to put Magento in maintenance mode because the uninstall script does that automatically.
2. Uninstall the Magento 2 Extension Using the module:uninstall Command
Execute the following command in your terminal:
<pre><code>
$ php bin/magento module:uninstall <Vendor_Name> --remove-data --clear-static-content
</code></pre>
The Magento module:uninstall command performs the following tasks:
1. Checks if the extension is defined as a Composer package.
2. Checks for dependencies.
3. Asks for confirmation before proceeding if there’s no dependency.
4. Puts Magento in maintenance mode.
5. Removes database schema and data defined in the extensions Uninstall classes.
6. Removes the extension from the setup_module database table.
7. Removes the extension from the app/etc/config.php file.
8. Executes the composer remove command and updates the Magento project requirements in the composer.json file.
9. Cleans Magento cache, updates generated classes, and clears static view files.
10. Disables maintenance mode.
Here’s what successful execution of the Magento uninstall command looks like in the terminal:
In case of errors, the command returns an output detailing the error. Troubleshoot the error based on the output received and rerun the module:uninstall command.
3. Check the Extension Status
You can verify the extension is uninstalled using the following command:
<pre><code>
$ php bin/magento module:status <VendorName>_<ModuleName>
</code></pre>
After verifying the module is disabled, switch Magento to the production mode, access your storefront in a browser, and verify everything works correctly. If you notice any errors, try clearing the Magento cache and running the setup:upgrade command.
If that doesn’t fix it, roll back to a previous version and reach out to your extension developer for assistance.
Final Thoughts: How To Uninstall an Extension in Magento 2
In addition to our guide, make sure you reference the extension documentation for extra steps to uninstall the extension in Magento 2.
Removing unwanted extensions can help you improve Magento store performance by reducing code conflicts. It also lowers the chances of your store being hacked due to unknown vulnerabilities in an outdated extension.
If you’re looking for more ways to secure Magento 2 and optimize its performance, sign up for Managed Magento hosting with Nexcess. Our plans include Magento-optimized hosting environments, nightly backups, and 24/7/365 security.
Browse our plans to get started today.