Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.In earlier versions of Drupal 8 the install_profile was always written to settings.php. This meant that, in code that did not run at install time, Settings::get('install_profile') was equivalent to drupal_get_profile().
There are instances where a hosting platform might make settings.php not writable. To allow this, if a distribution is used and settings.php is not writable, the installer no longer writes the install profile to settings.php.
To access the install profile in Drupal 8 use \Drupal::installProfile() or inject the install_profile container parameter into your service.
drupal_get_profile() has been deprecated and will be removed in Drupal 9. Settings::get('install_profile') will not be supported in Drupal 9 either.
Changing an existing install profile
In order to change an existing sites installation profile you need to copy any modules provided by the profile into your modules/ directory. You can then add a hook_update_N function to your installation profile or create a helper module. The hook_update_N() should:
\Drupal::service('module_installer')->install(['minimal']);
\Drupal::configFactory()->getEditable('core.extension')
->set('profile', 'minimal')
->save();
\Drupal::service('module_installer')->uninstall(['my_profile']);
Alternatively I would consider creating a one-off drush script to do this change since having two profiles and changing the install profile are risky activities.
Comments
Code snippet is wrong
AFAIK it should be:
Worked for me
Worked for me changing over a site's install profile, thank you for posting
Updated snippet
As drop moves on, installation profile has also it's own entry in modules array, inside of core.extension config, This can throw some errors when you'll try to import CMI after switching profile. Updated version of your code would be:
:-)
This is great -- thanks! I
This is great -- thanks! I just had to tweak it a little because the new profile wasn't being found/recognized.
Per https://www.drupal.org/project/profile_switcher/issues/3121985
I added this line to the top:
\Drupal::service('extension.list.module')->reset()->getList();So the full script for me is:
Profile Switcher
This can now be done with Profile Switcher module, which incorporates all of the above. If you have additional changes, please contribute over there.