Migrate a Composer-based Drupal Site to a Build Tools Site
Migrate a Drupal site created via Pantheon Dashboard (or Terminus) to a Build Tools-based site.
This guide shows you how to migrate a Composer-based Drupal site (site created via Pantheon dashboard or Terminus) to a Build Tools-based site.
If this is not your scenario, see Drupal Migration Guides for additional upgrade paths.
Overview
Drupal sites on Pantheon have Integrated Composer built-in to manage site dependencies. A Drupal site with Build Tools also provides site dependency management, as well as an external repository and a Continuous Integration workflow setup.
The goals of this migration are to:
-
Create a new Drupal site in Pantheon using the Terminus Build Tools plugin
-
Import your existing codebase, database, and files into your new site
Will This Guide Work for Your Site?
Confirm that your site meets the following requirements before you continue:
-
Ensure your site has the Pantheon
drupal-composer-managedrepository in its upstream.-
Use Terminus to confirm the
drupal-composer-managedUpstreamRun the command
terminus site:info $SITEto display the site's basic information and properties.The following is an abridged example of the output for a site upstream set to
drupal-composer-managed:
The following values indicate that a site is using a
drupal-composer-managedupstream:-
The
Frameworkisdrupal8 -
The
Upstreamincludeshttps://github.com/pantheon-upstreams/drupal-composer-managed.git
-
- You are able to create a new Drupal site using Terminus Build Tools
Before You Begin
Clone your existing site to your local environment following the git clone command from the dashboard.
The existing site's commit history will no longer exist after migrating to the new site.
Create a New Terminus Build Tools Drupal Site
- Follow the Terminus Build Tools Documentation to create a new Drupal site:
- Wait for the site to be created and for the first build to complete.
Prepare the Local Environment
-
Review our documentation on Git, Composer, and Terminus, and install and configure them on your local computer. Pantheon requires Composer 2 at minimum.
- Mac users can use Homebrew to install Git, Composer, and PHP, along with their required dependencies. Restart the shell or terminal environment after entering the following command:
-
Get a local copy of both your new site (from the external repository) and your existing site codebase.
-
Set the following temporary variables in your terminal session to match your folders location and sites names:
Copy Existing Configuration
Copy any existing configuration from the source site and update the source path as needed to match your configuration folder:
It is possible that the Drupal site might have relocated the configuration path to a different location. You can find your config.yaml files are via:
In some cases no files are copied through this step. This is not cause for concern.
Add Contributed and Custom Code
This section describes how to replicate your selection of contributed modules and themes, and any custom modules or themes your development team has created in your new project structure.
Contributed Code
The goal of this process is to have Composer manage all the site's contrib modules, contrib themes, core upgrades, and libraries (referred to as contributed code). The only items from the existing site that should remain in the Git repository are custom code, custom themes, and custom modules that are specific to the existing site.
Modules and Themes
Your site should already be managing contributed modules and themes through Composer. Follow the steps below to migrate these items to a new site.
-
Open the source site
composer.json. -
Run the
composer requirecommand for each module and theme in the$DESTINATIONdirectory:
You can require multiple packages in the same command if desired.
Other Composer Packages
If you added non-Drupal packages to your site via Composer, use the following steps:
-
Run the command
composer requireto migrate each package. -
Use the following command to display the differences between the versions of
composer.json:
Libraries
Libraries can be handled similarly to modules, but the specifics depend on how your library code was included in the source site. If you're using a library's API, you may have to do additional work to ensure that it functions properly.
Do not forget to commit your changes during these steps.
Custom Code
Manually copy custom code from the existing site repository to the Composer-managed directory.
Modules and Themes
- Run the following commands to move modules:
- Run the following commands to move themes:
Use the above commands to move custom code (if any) to your new site.
settings.php
Your existing site may have customizations to settings.php or other configuration files. Given that both sites ($SOURCE and $DESTINATION) have been created from the same upstream, it is ok to replace the $DESTINATION settings.php with the one coming from the $SOURCE site:
The resulting settings.php should not have a $databases array.
Additional Composer Configuration
Any additional Composer configuration that you have added to your site should be ported over to the new composer.json file. This can include configurations related to repositories, minimum-stability, or extra sections.
- Use the
diffcommand to get the information you need to copy:
- Commit your changes as needed.
Push to the External Repository Master Branch
- Push to the master branch in the external repository:
- Confirm that the Continuous Integration workflow succeeds in committing your code changes to the Pantheon site.
Add Your Database
The Database import requires a single .sql dump that contains the site's content and configurations.
-
Create a
.sqldump using the mysqldump utility. -
Compress the resulting archive with gzip to reduce the size for a faster transfer:
- Replace
USERNAMEwith a MySQL user with permissions to access your site's database. - Replace
PASSWORDwith the MySQL user's password. To force a password prompt, move-pto the end of the command and leave it blank. This prevents your MySQL password from being visible on your terminal. - Replace
DATABASEwith the name of your site database within MySQL. ~/db.sqldefines the output target to a file nameddb.sqlin your user's home directory. Adjust to match your desired location.
The resulting file will be named db.sql.gz You can use either the Pantheon Dashboard or a MySQL client to add your site's database.
-
Select the Dev environment in the Site Dashboard.
-
Select Database / Files.
-
Click Import and add your archive accordingly (based on file size):
Back Up the tokens.json file
- Connect to your site using SFTP command or credentials from your dashboard and get a backup of the following file:
- Use the SFTP
getcommand to download the file to your local directory (this is only for SFTP command line use):
Upload Your Files
Files refer to everything stored inside sites/default/files. This usually consists of uploaded images, generated stylesheets, aggregated scripts, etc. Files are not under Git version control and are stored separately from the site's code.
You can use the Pantheon Dashboard, SFTP, or Rsync to upload your site's files.
Follow the steps below to export a tar.gz or .zip file of your directory files.
- Export a
tar.gzor.zipfile of your files directory:
Navigate to your Drupal site's root directory to run this command, which will create an archive file in your user's home directory:
-
Select the Dev environment in the Site Dashboard.
-
Select Database / Files.
-
Click Import and add your archive accordingly (based on file size):
Restore tokens.json file
- Connect to your site using SFTP command or credentials from your dashboard to restore the backup of the
tokens.jsonfile:
- Use the SFTP
putcommand to upload the file from your local directory (only if using the SFTP command line):
You must run this from the directory where the tokens.json backup was downloaded.
You should now have all three of the major components of your site imported into your new site and CI should be working.
- Clear the caches on the Pantheon Dashboard.
Troubleshooting
Provided Host Name Not Valid
Update your settings.php file with a trusted host setting, if you receive the following error message:
Refer to the Trusted Host Setting documentation for more information.
Working With Dependency Versions
Version compatibility issues can occur when packages pulled by Composer are updated along with their dependencies. If this happens, you will need to manually alter the version constraints on a given package in the require or require-dev section of composer.json to update the packages. Refer to the updating dependencies section of the Composer documentation for more information.
Troubleshoot package updates by running composer update. This updates composer.lock to the latest available packages. Package updates are constrained by version requirements in composer.json.