You go to reinstall a module that you have previously uninstalled/deleted and you receive the message:
Unable to install [module], [module files] already exist in active configuration.
What Drupal is telling you here is that there are still dormant files from the previous install within your database. You are attempting to create 'new' versions of these files by reinstalling the module but Drupal won’t comply because, as far as it’s concerned, the module is already installed. This is very frustrating because the module will not be listed in Extend and you no doubt have attempted to add and remove it several times from the admin interface and/or site file directory.
The obvious solution is to find these malingering files, delete them, and then install them again, this time with a 'clean' configuration where the module files are created anew. This is easier said than done however and often a simple Ctrl+F applied to your site’s file directory may not be sufficient to identify them.
There are two methods you can try. I recommend starting with the first and if this doesn’t work, move onto the second. The second method is the most fool-proof, however it carries greater risk as it requires you to interact with the database directly.
1. Configuration export
We are going to download a complete configuration file, remove the dormant files and then re-upload the config. By working with what is effectively a clone of our module setup we reduce the risk of an error upsetting our live site components.
Navigate to Configuration >> Development and select Configuration synchronization
Select the 'Export' pane and then click the Export button.
This will download the configuration snapshot to your machine. Extract the file and then search for the files belonging to the module you are trying to reinstall, then delete them.
Next, we need to re-upload the config, this time without the malingering files that were causing us trouble. The modified config file will need to be uploaded to Drupal in the same compressed format that we downloaded it in: tar.gz. If you don't know how to do this, please consult my article How to create and extract tar.gz files.
Then once again go to Configuration synchronization but this time select 'Import'.
Finally clear the Drupal cache and your browser cache (just to be sure) and attempt to reinstall the module in question. Hopefully it should install without a hitch.
2. Remove files directly from the database
So the first method didn't work? Don't worry, there is something else we can try. This requires us to operate directly on the live site however so we must be careful.
I would recommend backing up your site again (just to be on the safe side) and then also putting your site in maintenance mode for the duration of the fix. This will effectively make your site inaccessible to users for a short period.
To activate maintenance mode, navigate to Configuration >> Development and select
Next you will need to login to PHPMyAdmin either via CPanel or your local server set up. Once in, select your sites database and then click on the config tab. This will show you all of your sites module files.
Select and delete the files, turn off maintenance mode and clear the Drupal cache. Now when you re-install the module, there should be no problems.