How to Remove Unused Modules in Drupal 8
One of the important aspects of keeping your Drupal 8 site up-to-date, secure and performing well is to remove unused modules.
There are a number of reasons why you would want to do this:
- Security – Every module should be kept up-to-date. If you’re not using a particular feature, you’re just giving yourself more work to do.
- Performance – Drupal is an event-based CMS so at every point in the page-build process, Drupal is checking to see if any module on your site wants to do something. All of this adds up!
- Site clutter – The “Extend” menu is long enough! Not to mention any configuration menu items that a module might add.
- Fluff – Some modules just don’t belong – Some development modules such as Devel should never be on a production server. It’s always best to remove those completely.
Step 1: Uninstall
When you install a module on your site, depending on the module, a number of things happen. Obviously the code is added to the /modules folder. However, if that module stores data in the database, then tables are created and sample data may be installed. It’s important to uninstall a module before you remove the code so the module’s uninstall configuration file can perform it’s tasks.
It’s also worthy to note that if you simply delete the code without uninstalling, you might encounter a huge performance regression which stems from Drupal recursively searching through the site for the “missing” module on every page load.
Caution: When you uninstall a module that does write data to the database, all your data will be deleted.
To uninstall a module:
- Log into your Drupal site and click on Extend -> Uninstall
- Find the module you wish to uninstall and put a checkmark in the box.
- Scroll down to the bottom of the page and click “Uninstall”.
If a module has dependencies, you’ll need to uninstall the module that requires something else first, then the main module second. For example, Admin Toolbar can not be uninstalled until Admin Toolbar Extras is uninstalled.
Step 2: Remove the module code from the codebase
As you may know, uninstalling a module in Drupal doesn’t actually remove the code from the codebase. The code stays in the /modules folder, ready to be installed again. It’s always safest to completely removed the code from your codebase.
If you do not have access to the codebase, you will need to ask your IT department or web host to do that for you. If your website is hosted on something like Acquia Cloud or Pantheon, those tools are built-in. If your site is hosted on a popular hosting service such as Hostgator, Hostmonster or Bluehost, you can do that via CPanel. If your site is hosted on a service such as Digital Ocean, you’ll need SSH access to delete the files. It’s beyond the scope of this tutorial to dive into every service, but suffice it to say, the files should be deleted.
Once you gain access to the codebase, you’ll look for the modules folder. Your module will be listed via the machine name. Just delete the entire folder. In the illustration below, to delete the Asset Injector module, you would delete the asset_injector folder.
One Final Thought
While it might be tempting to uninstall Core modules that you’re not using, it really won’t help. The modules you remove will be reinstalled on the next Drupal update regardless.
[quote]While it might be tempting to uninstall Core modules that you’re not using, it really won’t help. The modules you remove will be reinstalled on the next Drupal update regardless.[/quote]
Thank you for this tutoria! I was just thinking that after uninstalling: if composer is used it’s best to remove the files using the composer remove command rather than erasing them manually.
I read in a video tutorial that ALL the modules listed under Admin->Extend->Uninstall may be uninstalled in principle. That is, provided they are not prereqs for some other items. I also understand that it doesn’t make sense to uninstall core modules for obivous reasons. Still, just to make sure again: ALL the modules listed? And – what happens to the config data? Are they deleted automatically when deleting modules or do I additionally have to delete those separately?
Does composr remove get rid of everything (module code, config, db-data)?
Thanks for your hints – and keep healthy….
Yes, any module that you can “un-check” can be uninstalled.
Yes – all config data will be lost (since the configuration is stored in the database).
RE: Composer – please read this thread: https://drupal.stackexchange.com/questions/277627/does-composer-remove-drupal-module-actually-uninstall-the-module-first
Overview from the post:
No, Composer doesn’t install or uninstall modules in the site itself.
It’s a dependency manager; all it does is compute your requirements, then download them.
You might be able to add a post install/update command to automate it, but trying to make it generic would probably be a pain.
Is your recommendation to first uninstall the module via Drupal Admin Panel and then run composer remove drupal/module ? Is that the proper way to do this?
Yes, if you remove the files before uninstalling the module there’s a good chance you’ll brick the site until you replace them.
hope that helps
please see my comments below re: composer
What happens to a Drupal site if a module is simply disabled (deleted/renamed) within CPanel? I find myself locked out as Admin because the Recaptcha module is incorrectly rejecting logins.
– thinking of updating with the latest security update and simply overwriting the modules folder… or just deleting within CPanel… but will that break the site?!
Thx for any advice
if you delete the module folder using the file manager in CPanel (or via SFTP etc)., your site won’t break, however you’ll lose any functionality that module provides (so – it “might” break – depending on the module). OF COURSE, we’re only talking about contributed modules here. We NEVER delete/hack a core file. 🙂
If you just delete the Recaptcha module – you should be fine – you’ll just lose that functionality.
As always — TAKE A BACKUP FIRST!!!
hope that helps.
Thanks so much for your help! This was really useful for someone just getting into Drupal. Bless you <3
That’s awesome!! So glad we could help.