Drupal 8: Install Site From Existing Configuration

Installing a Drupal site from configuration is useful when running tests or if you don't have a copy of the database. You'll get a copy of the Drupal site without any content that will act in the same way as the live site. You can use modules like default content to add content into the mix so your newly installed site acts a little bit more like the live version.

Since there are some prerequisites to get this up and running I thought I would run through what is needed to get this working and how to run it.

Install Profile Compatibility

Firstly, there is a small issue regarding the hook_install() hook on install profiles that means you'll need to use an install profile that doesn't contain one. The reason for this is that when you have completed your install, importing the config and the needed modules, the install hook will trigger and potentially change the config that you've just installed. To limit the complexity and scope of the change it was decided to simply reject the ability of profiles containing hook_install() hooks from being used.

If you have installed your site using the standard profile (which is probably the case) then you'll see an error like this.

  Configuration install: standard                                                                                  
                                                                                                                   
  The selected profile has a hook_install() implementation and therefore can not be installed from configuration. 

To swap your site to use the minimal profile Use the minimal install profile or any other install profile without a hook_install() hook. To do this in your config you just need to open up the core.extension.yml file and change the profile setting AND the profile name in the list of installed modules. Even though it's not a module it will still appear there so you need to change both instances.

You need to change the core.extension.yml file from this:

  menu_link_content: 1
  pathauto: 1
  content_translation: 10
  views: 10
  paragraphs: 11
  standard: 1000
theme:
  stable: 0
  classy: 0
  bartik: 0
  seven: 0
  adminimal_theme: 0
profile: standard
_core:
  default_config_hash: .....

To this:

  menu_link_content: 1
  pathauto: 1
  content_translation: 10
  views: 10
  paragraphs: 11
  minimal: 1000
theme:
  stable: 0
  classy: 0
  bartik: 0
  seven: 0
  adminimal_theme: 0
profile: minimal
_core:
  default_config_hash: .....

Swapping out 'standard' for 'minimal'.

By the way, it looks like this requirement will be removed from future versions of Drupal (probably from 9.1.0 onwards). See this issue on Drupal.org for more information on this.

Exporting Config

If you already have config exported you can probably skip this step.

Ensure that your config_sync_directory setting is set in your site settings.php file. This is required by Drupal to know where your config will live.

$settings['config_sync_directory'] = '../config/sync';

With that in place, and the directory created, export your config using drush.

drush cex

This will place your Drupal configuration into the directory located at ../config/sync.

Running The Install

You can now install the site entirely from fresh using the site:install drush command, along with the --existing-config flag.

drush site:install --existing-config

This will drop all the tables in your database and re-install your site using your previously exported configuration.

Here is some example output from the command running.

$ drush site:install --existing-config

 You are about to:
 * DROP all tables in your 'drupal' database.

 Do you want to continue? (yes/no) [yes]:
 > yes

 [notice] Starting Drupal installation. This takes a while.
 [notice] Performed install task: install_select_language
 [notice] Performed install task: install_select_profile
 [notice] Performed install task: install_load_profile
 [notice] Performed install task: install_verify_requirements
 [notice] Performed install task: install_write_profile
 [notice] Performed install task: install_verify_database_ready
 [notice] Performed install task: install_base_system
 [notice] Performed install task: install_bootstrap_full
 [notice] Performed install task: install_config_import_batch
 [notice] Performed install task: install_config_download_translations
 [notice] Performed install task: install_config_revert_install_changes
 [notice] Performed install task: install_configure_form
 [notice] Cron run completed.
 [notice] Performed install task: install_finished
 [success] Installation complete.  User name: admin  User password: ....

If you want to see the original change record for installing Drupal from an existing configuration.

Comments

Thank you for the instructions, it's June 2022 and they still work great! 🎉

The only note you could add, but it's not a problem, just an extra tip: Drupal can be installed with existing config in browser/via the UI, as seen in the screenshots on the issue thread related to the "install from existing config" functionality: https://www.drupal.org/project/drupal/issues/2980670  (It still uses drush in the background.)

Permalink

Thanks for reading Alison. Really appreciate the extra tip as well! :)

Name
Philip Norton
Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
5 + 12 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.