Abstract: The following case breaks down Drupal work into sections, focusing on what the issue was, how we diagnosed it, and the steps taken to resolve it.

 

Troubleshooting and Resolving Drupal Module Installation Issues

Below we outline the process for diagnosing and resolving issues related to installing and enabling Drupal modules using Composer and Drush.

Specifically, it covers the successful installation and configuration of the Metatag module, but it can be used with any module.

1. Introduction
During website maintenance and SEO setup for a Drupal site, we encountered issues with installing and enabling the Metatag module. Despite Composer reporting a successful installation, Drush could not recognize or enable the module. This SOP describes the step-by-step process followed to troubleshoot and resolve the issue.

2. Problem Identification
Initial Issue: The main challenge was that after installing the Metatag module via Composer, Drush could not enable the module due to a "missing module" error.
  
Error Message:
Composer reported a successful installation, but the module was not found in `/modules/contrib`.

 

Drush output: 
    Unable to install modules metatag due to missing modules metatag.

3. Tools and Commands Used

  • Tools:
    Composer: For installing and managing Drupal modules.
    Drush: For enabling modules and clearing cache.
    Terminal/SSH (bash): For accessing the server and running necessary commands.
  • Common Commands:
    `composer require drupal/metatag`
    `drush en metatag -y`
    `drush cr`
    `ls /path/to/modules/contrib/metatag` (to check module installation location)

 

4. Diagnosis and Analysis

  • Step 1: Verify the existence of the module in `/modules/contrib` directory. Running the command `ls /path/to/modules/contrib/metatag` showed that the Metatag module was not in the expected directory.
  • Step 2: Review the `composer.json` file for potential misconfigurations, particularly in the `"installer-paths"` section, which defines where modules should be installed.
  • Step 3: File permissions were checked and adjusted to ensure proper access to module directories. The issue could also have been due to incorrect permissions preventing Drupal from accessing the module.

 

5. Solution & Implementation Steps

  • Step 1: Correcting `composer.json` File
    The `"installer-paths"` section of `composer.json` was updated to ensure modules are placed in the `modules/contrib` directory. The correct format for this is:
    json
      "extra": {
          "installer-paths": {
              "modules/contrib/{$name}": ["type:drupal-module"],
              "themes/contrib/{$name}": ["type:drupal-theme"]
          }
      }

 

Step 2: Reinstalling the Metatag Module

  • Remove the module:
    bash 
    '
    composer remove drupal/metatag'
  • Reinstall the module using Composer:
    bash
    'composer require drupal/metatag'

 
  
Step 3: Verify Installation

  • Check that the module is now present in the `modules/contrib` directory:
    bash
    'ls -l /bitnami/drupal/modules/contrib/metatag'

 

Step 4: Clear Drupal Cache

  • After reinstalling, clear Drupal’s cache to ensure changes are reflected:
    bash
    'drush cr'

 

Step 5: Enable the Module

  • Enable the Metatag module using Drush:
    bash
    'drush en metatag -y'
     

6. Lessons Learned and Best Practices

  • Proper `composer.json` configuration: Always ensure that `"installer-paths"` in `composer.json` are correctly set for module and theme installation.
  • Permissions: Ensure that the appropriate file permissions are set for the module directories so Drupal can access and enable modules without issues.
  • Clear Cache: Always clear Drupal's cache after making significant changes, such as installing or enabling new modules.

 

7. Conclusion
The issue was resolved by correcting the `composer.json` file, reinstalling the module via Composer, and ensuring proper file permissions. Once these steps were completed, the Metatag module was successfully enabled, allowing further SEO configuration on the site.

 

Please feel free to contact us if you need help with Drupal.

 

 

 

 

Confidentiality
No