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?
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
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.
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
config
table where name = 'core.extension'
and
remove the module from the data blob which is a serialized array.(...s:6:"module";a:HERE;{...)
cache_config
table from phpmyadmin or using command-line.i:0;s:8:"name of the module";
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.
$a = 'DATA_COLUMN_FOR_CORE_EXTENSION_ROW'; $b = unserialize($a); unset($b['module']['MACHINE_MODULE_NAME']); $c = serialize($b); print $c;
Do this:
rm -rf modules/your_stubborn_module
rm -rf sites/default/files/php
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
In Drupal 8, try to removing the module from your module folder and run rebuild.php.
Try drush pm-uninstall module-name
as well.
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 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)
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.
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.
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.
This resolved the issue. This is based on my interpretation of https://www.drupal.org/node/2487215
There is a module for that. This module was posted in Aug-2013 on drupal.org. In case somebody needs.
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.
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...