Configure CiviCRM 5 with D8 using Lando

Objective

CiviCRM is an old Drupal 7 friend and its relationships with Drupal 8 are in a pretty good way. 
CiviCRM is published as a suite of related packages. Our goal is to use Composer to add CiviCRM's packages to the D8 site.
Lando will host the party by spinning up a local environment, however, this method should be generalizable with any other development environment.

Recipe Type
Status
Idea
Drupal Version
Recipe Tags
Notes
Steps to Build

A better way to install CiviCRM on Drupal 8:

  • Create a new Drupal 8 site with CiviCRM (replace 'some-dir' with the directory to create)
    composer create-project roundearth/drupal-civicrm-project:8.x-dev some-dir --no-interaction
  • Adding CiviCRM to an existing Drupal 8 site :
    composer require civicrm/civicrm-asset-plugin civicrm/civicrm-drupal-8 civicrm/civicrm-packages
  • Installing CiviCRM. 

Other old fashion approch, Get Drupal and install it

  • Create a Drupal project
    composer create-project drupal-composer/drupal-project:8.x civicrm-drupal --stability dev --no-interaction
  • Initialize Lando
    cd civicrm-drupal
    lando init --recipe drupal8 --webroot web
  • Give your app the CiviCRMDrupal name then start Lando
    lando start
  • Finally, install Drupal
    lando drush site-install standard --account-name=admin --account-pass=admin --db-url='mysql://drupal8:drupal8@database/drupal8' --site-name=CiviCRMDrupal

Get CiviCRM for Drupal 8

Run the following commands at the root of the civicrm-drupal directory

  • Set CiviCRM version
    CIVICRM_VERSION=5.6.0
  • Repositories aren't inherited from requirements, so we have to put this one from civicrm-core/composer.json again
    composer config repositories.zetacomponents-mail vcs https://github.com/civicrm/zetacomponents-mail.git
  • Require civicrm-core at the requested version
    composer require "civicrm/civicrm-core:$CIVICRM_VERSION"
  • Download the latest Drupal package to copy some stuff that's generated by the build and included in release tarballs.
    wget -O /tmp/civicrm.tar.gz https://download.civicrm.org/civicrm-$CIVICRM_VERSION-drupal.tar.gz
    tar -xzf /tmp/civicrm.tar.gz -C /tmp
  • Copy the 3rd party dependencies. Should be done via Composer at a later stage
    cp -r /tmp/civicrm/packages vendor/civicrm/civicrm-core/
  • Set up the civicrm-version.php
    cat /tmp/civicrm/civicrm-version.php | sed -e 's/Drupal/Drupal8/' > vendor/civicrm/civicrm-core/civicrm-version.php
  • Copy SQL
    cp -r /tmp/civicrm/sql vendor/civicrm/civicrm-core/
  • Copy some misc other things
    cp /tmp/civicrm/civicrm.config.php vendor/civicrm/civicrm-core/
    cp /tmp/civicrm/CRM/Core/I18n/SchemaStructure.php vendor/civicrm/civicrm-core/CRM/Core/I18n/
    cp /tmp/civicrm/install/langs.php vendor/civicrm/civicrm-core/install/
  • Clean-up
    rm -rf /tmp/civicrm.tar.gz /tmp/civicrm

Get Drupal 8 CiviCRM module

  • Get the module from GitHub. We will use the 5.7.x-dev that requires CiviCRM Core >=5.4.0
    composer config repositories.civicrm-drupal vcs https://github.com/civicrm/civicrm-drupal-8.git
    composer require civicrm/civicrm-drupal-8:5.7.x-dev

Install CiviCRM

  • Go to /admin/modules and enable the CiviCRM Core module
  • You will have this error while trying to access /civicrm in the browser
    Note: Sorry, due to an error, we are unable to fulfill your request at the moment.
    You may want to contact your administrator or service provider with more details about what action you were performing when this occurred.
    DB Constraint Violation - contact_id should possibly be marked as mandatory for DashboardContact, create API. If so, please raise a bug report.
    To get rid of it, go back to Drupal, logout and login again. See CRM-19878.

Allow CiviCRM to be accessed from the docroot

  • CiviCRM will need to access its Javascript/CSS assets, so we will symlink the civicrm-core directory in the Drupal libraries directory.
    mkdir web/libraries (cd web/libraries/ && ln -s ../../vendor/civicrm/civicrm-core civicrm)
  • Configure then the CiviCRM Resource URL at /civicrm/admin/setting/url?reset=1, set the following value:
    [cms.root]/libraries/civicrm/

Execute scheduled Jobs via the cron

  • Install CV (the CiviCRM CLI) then execute this command via a system cron, in the docroot
    cv api Job.execute

Happy CiviCRM hacking!

Supporting Organizations
Participants