39

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?

32

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.

  • 1
    In terms of uninstalling modules I think this is the best solution. – David Apr 7 '17 at 10:54
  • 1
    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. – sillygwailo Jul 10 '18 at 18:23
  • Cheers for the lazy one liner! Missing a quote at the end though – Matt Fletcher Aug 20 '18 at 14:39
  • 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. – Adaddinsane Aug 23 '18 at 8:52
16

Do this:

rm -rf modules/your_stubborn_module
rm -rf sites/default/files/php
  • Depending on the module, you might have to delete some entries from the config table (see valli's answer) and some other tables. – Turion Jun 4 '16 at 10:01
  • This didn't work for me. – rooby Oct 31 '17 at 22:20
  • You have to run drush cache-rebuild too – Sky Dec 26 '17 at 13:20
16
  • 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.
  • 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 Jul 30 '15 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 Nov 23 '16 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 Jan 10 '18 at 3:31
3

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.

  • 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 May 15 '13 at 11:06
  • @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 Aug 7 '13 at 8:38
  • 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 Aug 26 '16 at 23:05
3

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

Try drush pm-uninstall module-name as well.

2

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)

2

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
1

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

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

protected by Community Sep 10 '18 at 0:41

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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