54

In Drupal 7, I could manually edit the {system} table in the database to disable a stubbon module. In my Drupal 8 site, this table is gone.

How can I manually disable a module in Drupal 8?

10 Answers 10

62

The Drupal 7 system table data is now stored in the config table in Drupal 8 against the core.extension parameter.

Solution 1: Update configuration

You can run the following code using drush eval or may be using the Devel module's provision to Execute PHP Code.

// Read the configuration.
$module_data = \Drupal::config('core.extension')->get('module');

// Unset the modules you do not need.
unset($module_data['MODULE_NAME']);

// Write the configuration.
\Drupal::configFactory()->getEditable('core.extension')->set('module', $module_data)->save();

You can do this all in a quick one-liner with drush.

drush eval "\$module_data = \Drupal::config('core.extension')->get('module'); unset(\$module_data['MODULE_NAME']); \Drupal::configFactory()->getEditable('core.extension')->set('module', \$module_data)->save();"

Solution 2: Edit config table if you cannot execute PHP

If the site is broken because of the problematic module and you can't even run PHP code, then may be you can edit the config table directly.

In the row in the config table where name = "core.extension" and edit the BLOB column data. The data is a serialized PHP array where you have to remove the module you want to get rid of from the module key of the configuration.

Solution 3: Fast and dirty solution

  • Remove the module from the file system
  • Truncate the table cache_config

However, this solution might result in messages saying the module does not exist in file system which mean something is wrong. But at least the broken module gets disabled and you can access your site in most of the cases.

Clearing Cache

Sometimes you might have to clear cache after following the above steps. Read this handy documentation on how to clear cache.

6
  • 2
    In terms of uninstalling modules I think this is the best solution.
    – David
    Commented Apr 7, 2017 at 10:54
  • 4
    If you need to uninstall a module but can't because the tables for the module are missing, you can use the third option with drush eval. An example one-liner is: drush eval "\$module_data = \Drupal::config('core.extension')->get('module'); unset(\$module_data['example_module']); \Drupal::configFactory()->getEditable('core.extension')->set('module', \$module_data)->save(); Note the escaped dollar sign so that the command line doesn't misinterpret $module as a Bash variable. Commented Jul 10, 2018 at 18:23
  • 1
    Cheers for the lazy one liner! Missing a quote at the end though Commented Aug 20, 2018 at 14:39
  • 1
    It's pretty much essential you do a cache clear, and then export config so the config doesn't try to re-install until you're ready. Commented Aug 23, 2018 at 8:52
  • 2
    After doing all the solutions listed there was still a system.schema entry in the key_value table for the missing module. Deleting that cleared out the warning.
    – liquidcms
    Commented Jan 14, 2020 at 17:47
21
  • Manually edit the config table where name = 'core.extension' and remove the module from the data blob which is a serialized array.
  • Be aware to decrement the module array length as well (...s:6:"module";a:HERE;{...)
  • Truncate the cache_config table from phpmyadmin or using command-line.
4
  • 1
    Thanks, this helped me. The answer should read "Manually edit the {config} table". The text portion to remove from the BLOB content is: i:0;s:8:"name of the module";
    – Hendrik
    Commented Jul 30, 2015 at 8:34
  • 2
    This answer helped solve a situation where a module could neither be uninstalled nor re-installed because a custom entity it defined was missing.
    – daniels
    Commented Nov 23, 2016 at 18:41
  • 1
    @hendrick this may have worked for you but the string to remove each module should be structured as s:8:"name of the module";i:0;. What @valli meant was that the array describing the number of modules should be decremented in number by the amount of modules removed. The begining of the blob in my setup is a:4:{s:6:"module";a:59:{, which is an array of 59 modules. If you delete two change that array value to 57.
    – dimmech
    Commented Jan 10, 2018 at 3:31
  • If you don't want to delete the module from the serialized value manually, use this php snippet to remove it: $a = 'DATA_COLUMN_FOR_CORE_EXTENSION_ROW'; $b = unserialize($a); unset($b['module']['MACHINE_MODULE_NAME']); $c = serialize($b); print $c;
    – Roger
    Commented Nov 27, 2019 at 11:52
16

Do this:

rm -rf modules/your_stubborn_module
rm -rf sites/default/files/php
4
  • Depending on the module, you might have to delete some entries from the config table (see valli's answer) and some other tables.
    – Turion
    Commented Jun 4, 2016 at 10:01
  • This didn't work for me.
    – rooby
    Commented Oct 31, 2017 at 22:20
  • 1
    You have to run drush cache-rebuild too
    – Sky
    Commented Dec 26, 2017 at 13:20
  • 1
    Thanks for this: this worked on our Drupal version "8.9.13". We, of course, had to purge the cache tables (cache_) as well. Commented May 29, 2022 at 0:40
7

If you need to update anything related to Drupal configuration, in this case core.extension, use Drush:

[Drush 8.x in this example]

drush cedit core.extension
5

In Drupal 8, try to removing the module from your module folder and run rebuild.php.

Try drush pm-uninstall module-name as well.

4

Consider using Drush. Drupal 8 is still defining what "disabling modules" should be. There is an ongoing discussion if there should be that option or it should be removed.

3
  • 1
    I'm developing locally on a windows PC and last time I looked Drush wasn't ready for Drupal 8. I'll have to look again.
    – bumpaw
    Commented May 15, 2013 at 11:06
  • 1
    @bumpaw Drush should work on Windows as well. That will at least help you locally. When it comes to production servers, I know many shared hostings don't provide you with Drush or even SSH which usually makes the management way more cumbersome. drush.org/drush_windows_installer
    – hampusn
    Commented Aug 7, 2013 at 8:38
  • 1
    And, using drush, how does one "manually remove" a module in a way that is different than the UI process? You don't appear to have answered the question.
    – 1kenthomas
    Commented Aug 26, 2016 at 23:05
4

I tried all of the other answers but kept getting a drupal error message. To solve it I had to remove a row from the key_value table (look for the module name in the name column)

3

This is how, I manually removed a module named "better_messages" from my Drupal 8 instance. As soon as I installed the "better_messages" module, the site went down. So there was no way to uninstall the module from user interface. I dont have Drush installed. I have done many settings given in forums, but this is how it finally worked for me.

1 Renamed the module to old_better_messages in modules folder.

  1. Through the url, ran http://IP:port/foldername/rebuild.php. This ensured that site is back, but only in read-only mode. I couldnt do the admin activities or edit articles.

  2. Used following command to delete the entry from database

DELETE FROM key_value WHERE collection='system.schema' AND name='better_messages';

In my case, there was no entry in the database. I think it might have got deleted because of the various stunts that I did earlier.

  1. Then using DB visualizer, I deleted entries from all the tables that starts with cache.

This resolved the issue. This is based on my interpretation of https://www.drupal.org/node/2487215

1
  • your solution worked like a charm! Thank you for sharing. Commented Jul 15, 2022 at 17:01
2

There is a module for that. This module was posted in Aug-2013 on drupal.org. In case somebody needs.

Disable modules

As stated on the page of this module,

Drupal 8 has removed the ability to disable modules for many reasons. See #1199946: Disabled modules are broken beyond repair so the "disable" functionality needs to be removed and many other issues in the queue of various core and contributed modules.

This module brings back the ability to (temporarily) disable modules from the UI or with Drush. Note, that there's no guarantee for your content, config or even your site after you disable a module.

0
1

Jigarius' answer above, sort of worked...

I had to: // Read the configuration.

$module_data = \Drupal::config('core.extension')->get()['module'];

Which should do the same thing. Not sure why it didn't work as Jigarius wrote it...

Not the answer you're looking for? Browse other questions tagged or ask your own question.