Installing a Local Copy of your Pantheon Drupal 8 site with Acquia DevDesktop

I recently signed up for a Pantheon account. I figured it was time to try out the platform. Getting sites up and running in Drupal 8 and the latest WordPress was fairly easy, and connecting with SFTP and GIT was not that difficult. But I noticed that Pantheon recommends Kalabox for local development, and that requires extra software on Windows that I haven’t yet installed. Even more interesting . . . Pantheon reps at a WordCamp conference this past weekend informed me that Kalabox is shifting to a command-line tool called “Lando” that is Docker-based and Pantheon is going to be following that shift to Lando.

So, to fend off the growing requirements, I thought I would try to install the Pantheon GIT clone of the Drupal 8 installation and database SQL dump on Acquia DevDesktop, which I have been using for general local development.

The first attempt to install was a disaster. It generated a completely untelling error message: “Internal Server Error. The server encountered an internal error or misconfiguration and was unable to complete your request.”

There are a few preparatory steps you need to take that are outlined on the Pantheon site, and in this article by Michael Anello, “Getting a Drupal 8 Pantheon Site up and running locally on Acquia DevDesktop”:

https://www.drupaleasy.com/quicktips/getting-drupal-8-pantheon-site-up-running-locally-acquia-dev-desktop

There are three main issues that affect local installation.

First, local installations of Pantheon Drupal require the inclusion of a settings.local.php file that contains local settings of your Drupal installation that might otherwise conflict with the Pantheon server installation. The file is programmatically #include(d) in the
regular settings.php file and excluded from your GIT repository so that it is not uploaded when you push code to the server. You should see the following in the settings.php that is downloaded in your Drupal 8 code:

/**
* If there is a local settings file, then include it
*/
$local_settings = __DIR__ . “/settings.local.php”;
if (file_exists($local_settings)) {
include $local_settings;
}

See step 2 below for creating a settings.local.php file. There is a default example.settings.local.php file that you can copy in the Drupal download.

Remember that you do not want to push (upload) the settings.local.php file to the server. In order to ensure that, you need to add settings.local.php to your .gitignore file. If you use the example .gitignore file from https://github.com/pantheon-systems/drops-8 , you will already have an entry to ignore settings.local.php in the file:

# Pantheon commits a settings.php for environment-specific settings.
# Place local settings in settings.local.php
sites/*/settings.local.php

But if you decide to use your own .gitignore, you can either open the file and add the line “sites/*/settings.local.php” (no quotes), or if you are using GIT Bash shell (which I use), you can change directory to the top-level website code folder that has the .gitignore file and run the following command, to append the line to your .gitignore file:

$ echo ‘sites/*/settings.local.php’ >> .gitignore

Second, in Drupal 8, ‘hash_salt’ cannot be an empty string (Drupal 7 does not care). However, the server instance of Pantheon Drupal 8 apparently populates the variable dynamically (probably from a file that is outside the project directory) and does not include its salt value in the download.  In order to make Drupal 8 work locally, you have to add the following ‘hash_salt’ value to the bottom of the settings.local.php file that you create.

$settings[‘hash_salt’] = ‘whatever_you_want_to_use’; // cannot be an empty string

Try using http://drupalhashsalt.com to get a random salt string.

Third, if you are importing data from an .sql dump file, you will need to run the local site’s update.php script. In order to do that without an error, you need to add the following to the end of your settings.local.php file:

$settings[‘update_free_access’] = TRUE; // Reset to FALSE after updating, for security reasons.

There are a few steps missing from Anello’s list. Here’s a list with the additional steps:

  1. Clone your Pantheon Drupal 8 site code repository with GIT.
  2. Copy sites/example.settings.local.php to sites/default/settings.local.php (ensure this file is listed in .gitignore).  You can find an example local Drupal 8 .gitignore file here: https://github.com/pantheon-systems/drops-8
  3. Add the following to the bottom of sites/default/settings.local.php: $settings[‘hash_salt’] = ‘some_random_string’;  If you want to generate a salt string, try http://drupalhashsalt.com .
  4. In order to import your existing database, you will need to run update.php, which requires that you have ‘update_free_access’ set to TRUE:
    $settings[‘update_free_access’] = TRUE; reset it to FALSE after running update.
  5. Backup the site online and download the database backup and unzip it to an .sql file in your code directory.
  6. Import the site using Acquia DevDesktop, using the “import from database dump file” for the database.
  7. Run update.php from your local DevDesktop site URL, something like this: http://sitename.dd:8083/update.php

site_import

You should be able to access the site with your server user name and password, which are included in the database.

Advertisements