Installing Drupal 8/CiviCRM on Pantheon

I've been exploring the workflow tools on the pantheon.io platform. This post describes our adventures in getting Drupal8/CiviCRM to work on Pantheon. If you have a pantheon.io account and if you have set up terminus https://pantheon.io/docs/terminus to interact with your pantheon projects then you should be able to follow along!

If you're not on Pantheon the steps are a little easier! First install Drupal - e.g.: 

composer create-project drupal/recommended-project:^8.9 myd8site.local

These follow these docs https://docs.civicrm.org/installation/en/latest/drupal8/ for the CiviCRM installation instructions.

1. Install the Drupal8/CiviCRM locally or on another server that you have command line access to

a) Create a designated directory, set your site_name to your project name (my project here is called citius88 -> the url is going to be citius88.ca) . Optional: hook it up to your organization account (if you have one on pantheon.io) and set your favourite region!

mkdir citius88
cd citius88
export PANTHEON_SITE_NAME="citius88"
terminus site:create $PANTHEON_SITE_NAME 'citius88.ca' empty --org 'Semper IT inc' --region 'Canada'
git clone https://github.com/pantheon-systems/example-drops-8-composer.git $PANTHEON_SITE_NAME
cd $PANTHEON_SITE_NAME
export PANTHEON_SITE_GIT_URL="$(terminus connection:info $PANTHEON_SITE_NAME.dev --field=git_url)"
git remote set-url origin $PANTHEON_SITE_GIT_URL

Head on over to your pantheon dashboard and you should see your new project! The following steps are required to get it up and functional:

b) Back in the shell on your local workspace: the next step is to remove the Continuous Integration bits. Delete the following directories and files:

rm -rf scripts/github
rm -rf scripts/gitlab
rm -rf .circleci
rm -rf .ci
rm -rf tests
rm bitbucket-pipelines.yml
rm build-providers.json
rm .gitlab-ci.yml

c) Modify composer.json:
Remove all dependencies in the require-dev section.
Update the scripts section to remove the lint, code-sniff, and unit-test lines.

d) Modify pantheon.yml
Remove the following section:

workflows:
sync_code:
after:
- type: webphp
description: Push changes back to GitHub if needed
script: private/scripts/quicksilver/quicksilver-pushback/push-back-to-github.php

e) Prepare for CiviCRM install
In composer.json -> update the requirement for minimum stability to:

 "minimum-stability": "dev",

f) Pull in CiviCRM! I'm using CiviCRM version 5.24.6 in this example - replace these digits with your favourite CiviCRM version. You can even use dev-master! When trying to composer require everything at once composer complained about memory_limit. I ended up having to set the php memory_limit to 3G! Here I'll describe the steps that work if you have less memory_limit to work with.

composer require civicrm/civicrm-core:5.24.6 --no-update
composer update --with-all-dependencies
composer require civicrm/civicrm-packages:5.24.6 --no-update
composer update --with-all-dependencies
composer require civicrm/civicrm-drupal-8:5.24.6 --no-update
composer update --with-all-dependencies
composer require civicrm/civicrm-asset-plugin:~1.0.1 --no-update
composer update --with-all-dependencies

composer civicrm:publish
# not sure this is needed
composer install

g) It's time to beam this up to Pantheon

composer run-script --no-dev prepare-for-pantheon
# this .gitignore file includes bower_components which when excluded results in interesting meltdown menus
mv vendor/civicrm/civicrm-core/.gitignore vendor/civicrm/civicrm-core/dontgitignore
# or something more elegant:
find -name .gitignore -delete
git status
terminus connection:set $PANTHEON_SITE_NAME.dev git
git add .
git commit -m 'Drupal8, CiviCRM and dependencies'
git push --force

h) It's time to install Drupal!

terminus connection:set $PANTHEON_SITE_NAME.dev sftp
terminus drush $PANTHEON_SITE_NAME.dev -- site-install -y
Installation complete.
User name: admin User password: XXXXXX
# visit your dev site - log in with the credentials above or create yourself a drush uli at any time:
terminus drush $PANTHEON_SITE_NAME.dev -- uli

i) And now CiviCRM! Because the /sites/default directory is not writable on pantheon after installing Drupal -> we followed this workaround.

terminus connection:set $PANTHEON_SITE_NAME.dev sftp
terminus connection:info $PANTHEON_SITE_NAME.dev
sftp -o Port=2222 dev.[connection:info].drush.in
# you can also find your SFTP connection info on your pantheon dashboard -> Connect with SFTP -> Username@Host
sftp> cd /srv/bindings/
sftp> ls
# note your project's hash
stfp>cd [hash]/code/web/sites
sftp> chmod 777 default
# install CiviCRM Core and CiviCRM Theme via GUI
sftp> chmod 755 default

j) Visit your Drupal8/CiviCRM site! You'll likely need to clear the usual CiviCRM caches and possibly Drupal caches as well.

2. Setting up a local development environment for your pantheon site.

To bring your local site to live and have the ability to easily pull code, database or files - you can do so by using Lando. Below is a list of the specific tools I use:

Because you'll be switching environments between pantheon and lando the civicrm.settings.php and civicrm.settings.inc files from the original roundearth projects are super handy!

Thusfar, the only small edits I made to the civicrm.settings.inc are:

-  $civicrm_paths['civicrm.root']['url'] = '/libraries/civicrm/';
+  $civicrm_paths['civicrm.root']['url'] = '/libraries/civicrm/core/';
-  $civicrm_setting['URL Preferences']['customCSSURL'] = '/libraries/civicrm/tools/extensions/org.civicrm.shoreditch/css/custom-civicrm.css';