Drupal 8: Install Site From Existing Configuration

19th August 2020 - 5 minutes read time

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.

  1. Configuration install: standard
  3. 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:

  1. menu_link_content: 1
  2.   pathauto: 1
  3.   content_translation: 10
  4.   views: 10
  5.   paragraphs: 11
  6.   standard: 1000
  7. theme:
  8.   stable: 0
  9.   classy: 0
  10.   bartik: 0
  11.   seven: 0
  12.   adminimal_theme: 0
  13. profile: standard
  14. _core:
  15.   default_config_hash: .....

To this:

  1. menu_link_content: 1
  2. pathauto: 1
  3. content_translation: 10
  4. views: 10
  5. paragraphs: 11
  6. minimal: 1000
  7. theme:
  8. stable: 0
  9. classy: 0
  10. bartik: 0
  11. seven: 0
  12. adminimal_theme: 0
  13. profile: minimal
  14. _core:
  15. 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.

  1. $ drush site:install --existing-config
  3. You are about to:
  4. * DROP all tables in your 'drupal' database.
  6. Do you want to continue? (yes/no) [yes]:
  7. > yes
  9. [notice] Starting Drupal installation. This takes a while.
  10. [notice] Performed install task: install_select_language
  11. [notice] Performed install task: install_select_profile
  12. [notice] Performed install task: install_load_profile
  13. [notice] Performed install task: install_verify_requirements
  14. [notice] Performed install task: install_write_profile
  15. [notice] Performed install task: install_verify_database_ready
  16. [notice] Performed install task: install_base_system
  17. [notice] Performed install task: install_bootstrap_full
  18. [notice] Performed install task: install_config_import_batch
  19. [notice] Performed install task: install_config_download_translations
  20. [notice] Performed install task: install_config_revert_install_changes
  21. [notice] Performed install task: install_configure_form
  22. [notice] Cron run completed.
  23. [notice] Performed install task: install_finished
  24. [success] Installation complete. User name: admin User password: ....

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

Add new comment

The content of this field is kept private and will not be shown publicly.