Hero Image

How to Setup a Database and Infrastructure on Pantheon for a Website Migration

Steps to Follow for Setting Up Database and Infrastructure on Pantheon

As opposed to Acquia, Pantheon doesn’t provide an option for having a secondary database, In Acquia cloud, we can just create a secondary database in our env. and import our D7 Database in that, and define the connection in settings.php

Step 1

In Pantheon, we have to first create a website, so click on the “Migrate Existing Website” Button, enter the Site name, URL, Organization, after that, it will give steps to download a database from an old Drupal 7 site. 

After that click on Continue, and it will take you to screen, where it will ask you either to import archive, or manually migrate it, we will choose “Manually Migrate”, and it will take us to the dashboard of the newly created website. 

Please follow the screenshots below:

Migrate Existing Sites

Migrate Existing Sites ^

Screenshot of process.

Enter Site Name and Organization ^

Instructions to Download Database from Old Website

Instructions to Download Database from Old Website ^

Click on Manually Migrate Link

Click on Manually Migrate Link ^

Click "Yes" to Migrate

Click "Yes" to Migrate ^

Click on "Visit Your Pantheon Site" Dashboard

Click on "Visit Your Pantheon Site" Dashboard ^

Click on "I've Successfully Migrated Manually"

Click on "I've Successfully Migrated Manually" ^

Step 2

After that you can click on “Connection info”, to get database details of the newly created website, as shown in the below screenshot.

Connection Details

Connection Details ^

To migrate our Old Database which we have created above, to our newly created website, we can use the below command.

mysql -u [user name] –p [password] [database_name] [tablename] > [dumpfilename.sql]

Or if your Drupal 7 Database Size is less than 100MB, then you can use the Import option in Databases / Files in left sidebar.

Import Database and Files to the Development Environment

Import Database and Files to the Development Environment ^

Step 3

After that, we will install terminus, a cli provided by Pantheon to interact with our site hosted on their platform.

For that, first, we have to install Terminus, we can use the below command.

mkdir ~/terminus && cd ~/terminus

curl -O
https://raw.githubusercontent.com/pantheon-systems/terminus-installer/master/builds/installer.phar && php installer.phar install

Step 4

Once the above command has been successfully run, then we will authenticate terminus.

Authenticating Terminus

Authenticating Terminus ^

If you are trying it for the first time, you will have to do it, using machine token.

However if you get an error like Command not found: Terminus, then you will have to edit .bashrc or.bash_profile, and add an alias for terminus.

alias terminus=/Users/manojbisht/vendor/bin/terminus

Step 5

After that, you will have to run either of these 2 commands in Terminal, depending on the file, which you have edited.

source ~/.bashrc

source ~/.bash_profile

Step 6

Once authentication is done, run site:list command to list site on Pantheon.

List Site on Pantheon

List Site on Pantheon ^

Here you can see, our site is showing, and it confirms our terminus is working fine.

Step 7

Now we will have to create secret using secret plugin to store credentials for our Drupal 7 Username and Password.

mkdir -p ~/.terminus/plugins

composer create-project -d ~/.terminus/plugins pantheon-systems/terminus-secrets-plugin:~1

We will first store mysql data in a variable D7_MYSQL_URL

export D7_MYSQL_URL=$(terminus connection:info site.env --field=mysql_url)

To store what value is being stored, we can run the command.

terminus connection:info sos_d8.dev --field=mysql_url

I have replaced the site with sos_d8 and env with dev, in above screenshot, as that is the env to whom we want to connect.

Step 8

After that, we will run the below command to set secret on our env. for a site.

terminus secrets:set site.env migrate_source_db__url $D7_MYSQL_URL

Here site will be replaced by our Drupal 8 site name, as found in terminus site:list, and env is the variable on which we want to create secrets, it can be dev, test or prod.

Please note as above command creates a secret environment basis, so if you want to access secrets variable in test environment, you will also have to create secret on that environment, using above commands.

Step 9

Now we have stored our credentials in our secret variable. We will be accessing that in our settings.php file.

To connect our Drupal 7 Site Database in Pantheon we will create a new key “drupal_7”, and fetch value from our secret plugin. To do that, we will first append below code in settings.php file.

# When on Pantheon, connect to a D7 database.
$migrate_settings = __DIR__ . "/settings.migrate-on-pantheon.php";
if (file_exists($migrate_settings) && isset($_ENV['PANTHEON_ENVIRONMENT'])) {
include $migrate_settings;

This is basically telling that, if we are on a Pantheon server, then also include our migrate_settings file.

and then in our setttings.migrate-on-pantheon.php, we will have below code.

$secretsFile = $_SERVER['HOME'] . '/files/private/secrets.json';
if (file_exists($secretsFile)) {
$secrets = json_decode(file_get_contents($secretsFile), 1);
if (!empty($secrets['migrate_source_db__url'])) {
$parsed_url = parse_url($secrets['migrate_source_db__url']);
if (!empty($parsed_url['port']) && !empty($parsed_url['host']) && !empty($parsed_url['pass'])) {
$databases['drupal_7']['default'] = array (
'database' => 'pantheon',
'username' => 'pantheon',
'password' => $parsed_url['pass'],
'host' => $parsed_url['host'],
'port' => $parsed_url['port'],
'driver' => 'mysql',
'prefix' => '',
'collation' => 'utf8mb4_general_ci',

The above code is basically fetching variables from our secret which we have set earlier, and setting the database array with those variable.

Step 10

Now run drush cr, using terminus below command.

terminus drush SXFV.dev -- cr

Here SXFV is name of our Drupal 8 website, as we got from terminus site:list

After that you can run a command like migrate-status, to check the status of various migrations.

terminus drush SXFV.dev -- migrate_status OR terminus drush SXFV.dev -- migrate_status --group=migrate_drupal_7

If you want to run a specific migration, you can run the below command.

terminus drush SXFV.dev -- migrate-import upgrade_d7_node_type

If you have installed migrate_manifest module, then you can run its command using the below command.

terminus drush SXFV.dev -- migrate-manifest manifest.yml

Manoj Bisht


Manoj is an Acquia Certified Drupal Developer with 7+ years of experience in Drupal 7, 8 and 9.


What Does a Website Product Owner Do?

The website product owners manage the digital experiences across a number of channels and address customers' needs to create valuable results for a company....


135 Laurier Ave. West, Suite 100
Ottawa, ON K1P 5J2
TEL: 1 (877) 257-6746

Saratoga Springs

153 Regent Street
Saratoga Springs, NY 12866
TEL: 1 (877) 257-6746