Skip to main content
Install Drupal 8 from existing Configuration

Have you ever tried to create an exact copy of your Drupal site without moving or sharing the database? This helps in a number of scenarios like:

Multiple developers work on the same project

You start a new project, do some initial work, export configuration and you then commit it to Git. Other developers clone the repository re-install from the configuration you exported and continue the development process from where you had stopped.
 

Automate the build process

More interestingly you want to automate the build process so that it can be easily reproduced at each stage (Dev, QA, Production)

In the above or other similar cases, we would need some way to install the Drupal from the pre-existing configuration which was exported from a different site. Here the solution which comes to your mind may be like install Drupal from scratch, set the configuration sync directory, and use config-import. But it won’t work because the Configuration Management System does not allow config-import between sites with different UUIDs and you run into an error that says:

“Site UUID in source storage does not match the target storage.”

To overcome this problem, we use the Drush site: install command with its new --existing-config option. However, this has a problem when using a profile that implements hook_install(). This issue is addressed in #2982052: Allow an install hook in profiles installing from the configuration.  In other words, this feature only works with minimal profile but does not work with Standard profile, and if you have used standard profile, you may see the following error:

“The selected profile has a hook_install() implementation and therefore cannot be installed from the configuration.”

No worries; we can create a custom install profile and will always use that to install from. In this case, I would recommend using the Install Profile Generator module which provides a simple Drush command to create an install profile.

To summarize the whole concept, we need the following few steps:

First, time install only:

  • Download and install Drupal as normal from scratch.
  • Install Drush for your site.
  • Download and Install the Install Profile Generator module. This module provides a simple Drush command for creating a new custom install profile. For example, if you want to create a new profile with the name “test” then run the command:

drush install-profile-generate --name=test

Apart from its original work this command also uninstalls the Install Profile Generator module.

  • Commit changes to Git and share with others.

For other developers who want to install this site:

  • Make sure the shared project has a custom install profile named “test” (in our case) under the profiles directory.
  • Create a database and user based on settings provided in the settings.php file.
  • Install the site with drush.

drush site: install test -y --existing-config

  • Change Drupal’s admin users password with drush command
  • drush upwd admin "password"
  • Make configuration changes and export configuration with the command:

drush cex

That is it. And after all, we can write a shell script to automate these steps.

Abdullah Shakir

Sr. Drupal Developer/ Module Developer/ Site Builder

Add new comment