Skip to content

Instantly share code, notes, and snippets.

@mparker17
Last active July 26, 2023 04:36
Show Gist options
  • Save mparker17/1e44a65c0550bcde620c803beb537c74 to your computer and use it in GitHub Desktop.
Save mparker17/1e44a65c0550bcde620c803beb537c74 to your computer and use it in GitHub Desktop.
Fixing a Drupal 8 site with an empty install profile

Fixing a Drupal 8 site with an empty install profile

You'll probably notice this because of a series of errors like the ones below on the status report at /admin/reports/status:

    Notice: Undefined index: name in system_requirements() (line 59 of core/modules/system/system.install).
    Notice: Undefined index: version in system_requirements() (line 61 of core/modules/system/system.install).

To fix this...

  1. Check settings.php and settings.local.php in the order they are parsed for lines that look like $settings['install_profile']

    This is just a sanity check to figure out if it is getting set properly earlier in the file, but unset or emptied ("stomped") later. If you find it's being unset or stomped, delete the line that stomps it.

    Drupal 8.5 and earlier shipped settings.php with an empty template line (this was removed in 8.6). The Drupal installer is supposed to set it, but sometimes fails to do so, which is often how this problem starts.

  2. Determine what install profile we want to set the site to use (we will call it $PROFILE in the rest of this document).

     drush -y sqlq "SELECT name FROM key_value WHERE collection = 'system.schema' AND name IN ('standard', 'minimal');"
    

    ... will check if Drupal had one at some point, but forgot about it.

    That command might return standard, minimal, or nothing (i.e.: an empty line).

    Note that if you suspect that Drupal was installed from a distribution like Umami, Thunder, Lightning, Commerce Kickstart, Panopoly, WETkit, etc. you'll have to add the distributions you suspect to the SQL IN clause.

    If it returns nothing, or you're otherwise unsure, then it's usually safe to assume minimal. The minimal profile only has the bare minimum modules and config required to run Drupal. Since you already have a (mostly-) working site, you already have a lot of other config making it work, so basing it on minimal won't break existing things.

  3. Optional: export config to be on the safe side:

     drush -y config-export
    

    ... you may also want to commit this to version control.

  4. Set the profile manually:

     drush -y ev "\Drupal::configFactory()->getEditable('core.extension')->set('profile', '$PROFILE')->save();"
    

    ... remember to replace $PROFILE with whatever you decided was going to be the new install profile in step 2.

  5. Set the profile weight:

     drush -y ev "\Drupal::configFactory()->getEditable('core.extension')->set('module.minimal', 1000)->save();"
    

    ... note that Installation profiles are like modules. 1000 is the default weight for the minimal and standard profiles on Drupal 8 sites whose installation finishes successfully.

    You can change 'module.minimal' to 'module.standard' (or any other install profile) if you prefer. Note, however, that install profiles are able to modify the behavior of the site (i.e.: by defining custom event handlers, implementing hooks, etc. as well as with default configuration). So, if you aren't certain which install profile was used, I recommend sticking with minimal, because it has the least amount of starting config and doesn't implement any hooks, define any event handlers, etc., and is therefore least likely to modify the behavior of your existing site.

  6. Ensure Drupal's database-update mechanism knows about the installation profile, so if future updates provide database updates for it, they are not skipped:

     drush -y sqlq "INSERT INTO key_value (collection, name, value) VALUES ('system.schema', '$PROFILE', 'i:8000;');"
    

    ... remember to replace $PROFILE with whatever you decided was going to be the new install profile in step 2.

    Unlike D7, update #8000 is the default when a module is installed, regardless of whether it implements any hook_update_N(). Also unlike D7, a value MUST be in this table in order for update.php to figure out that something needs to be updated!

  7. Edit settings.php (NOT settings.local.php or settings.pantheon.php, etc.) to specify the install profile:

     $settings['install_profile'] = '$PROFILE';
    

    ... remember to replace $PROFILE with whatever you decided was going to be the new install profile in step 2.

    Recall that best practice nowadays is to put sensitive / machine-specific credentials in settings.local.php, and commit settings.php so that settings like this one, hash_salt, etc. can be shared by all copies of this site. So you probably want to commit this change. In version control systems like Git where it is possible to commit something then ignore future changes, you may need to explicitly git add the file.

  8. Optional, export configuration again, then import it:

     drush -y config-export
     drush -y config-import
    
  9. Clear caches from /admin/config/development/performance, or by running drush -y cr

  10. Visit /admin/reports/status to check that you don't have any errors. In particular, you should see an item in the "Checked" section that looks like:

    Installation profile: $LABEL ($PROFILE-$VERSION)
    

    ... where $PROFILE is whatever you decided was going to be the new install profile in step 2, $LABEL is the human-readable name for that install profile, and $VERSION is the version of that install profile (i.e.: the Drupal version for minimal and standard)

Related error: unable to load module with empty machine name

After performing the above steps, you may get errors that look like:

    Warning: The following module is missing from the file system: in /app/core/includes/bootstrap.inc on line 268

... note the empty string between "system:" and "in" (the string template is 'The following @type is missing from the file system: @name').

This can happen because, if no install profile is set, then newer versions of Drupal 8 will assume the install profile is named NULL or an empty string, and certain operations will result in that empty profile being added to the list of things to load on bootstrap. This is likely to happen if a newer version of Drupal 8 ran for a bit without an install profile.

To fix this, all you need to do is delete Drupal's knowledge of it:

    drush -y sqlq "DELETE FROM key_value WHERE collection = 'system.schema' AND name = '';"

... and clear caches from /admin/config/development/performance, or by running drush -y cr

@f1rf1n
Copy link

f1rf1n commented Mar 9, 2021

Thanks very much for this. Got rid of the last of my updating troubles. Some minor points (I had to apply these to get my site back into a fully operational state) :

Shouldn't (in step 5)
->set('module.minimal') be
->set('module.[$PROFILE])' ?

Also in step 9 :
drush -y cr all <-- this gives my install errors ( Too many arguments, expected arguments "command". )
Why not just:
drush cr ?

@mparker17
Copy link
Author

mparker17 commented Mar 9, 2021

Shouldn't (in step 5)
->set('module.minimal') be
->set('module.[$PROFILE])' ?

Yes... you can substitute whatever profile you want. I put minimal in my document because:

  1. minimal assumes the least configuration, and doesn't modify any forms (i.e.: so it is least likely to change the existing site's behavior) and,
  2. I was writing this gist to make it easy for my co-workers at the time (who were new to Drupal) to copy and paste

Also in step 9 :
drush -y cr all <-- this gives my install errors ( Too many arguments, expected arguments "command". )
Why not just:
drush cr ?

The -y just gets rid of the prompt.

The extra all was a mistake (I'm accustomed to D7)... I'll update the document. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment