Civicrm Drupal 9
Oct 18, 2017 Synchronize CiviCRM Contacts with Membership Status to a specified Drupal Role both automatically and manually. Yes @kdvgent, I can confirm that the instructions from David Snopek works with the latest versions of Drupal and Civicrm.This is great. I used 'The full, manual process' with: Drupal 8.6.4; CiviCRM 5.8.2; That was not easy. You need composer, bower, git and wget.
This guide covers standard installation of CiviCRM on an existing Drupal 8 or 9 site. It assumes that you previously completed these tasks:
- Install Drupal 8or 9, and...
If you plan to develop patches for CiviCRM on Drupal 8 or 9, then please read the Developer Guide for information about Buildkit and civibuild.
Get the code¶
Drupal 8 (D8) and Drupal 9 (D9) sites are typically administered with Composer. Composer is a dependency management tool which can add, upgrade, and remove software packages for your site.
CiviCRM is published as a suite of related packages. Our goal is to use Composer to add CiviCRM's packages to the D8 site.
If you do not work regularly with Drupal 8 or 9 and Composer, then you should take a refresher before installing CiviCRM.
composer
Composer requires shell access to the D8/D9 site. It defines a command composer
.
Many D8/D9 sites are initialized via composer
, which means that composer
is already available. Thiscan be confirmed in the shell by running composer --version
:
It is possible that your system does not have composer
-- for example, if you used a tar-based installation of D8,then you may never have needed composer
before.
If composer
is missing, then you must download and install it first.Additionally, you probably need to set composer's memory limithigh enough for D8/D9.
Once you have composer
, you need to navigate to the composer-root. You can recognize it by the following:
- It has the files
composer.json
andcomposer.lock
. - It has a subfolder
vendor/
. - It usually has a subfolder
web/
(the web-root); alternatively, it may be the web-root.
A typical file-hierarchy might look like:
To work with composer
and D8/D9, you must open a shell and navigate to the composer-root, e.g.
Note: Drupal 9 and CiviCRM combinations require use of Composer 2.x.x
If composer
is properly installed, then these example commands will add CiviCRM to D8 or D9:
You should adjust the example path (/var/www/drupal.example.org
) and the example version (~5.35
) as needed.
If you'd like more details to understand these commands or common errors, then please drill-down below.
A handful of packages used by CiviCRM require extra patch-files.
This is possible with the popular cweagans/composer-patchesplugin. However, you must opt-in to enable it.
For any package in composer
, there may be several available versions. Some have an official, well-defined nameor number (e.g. v1.2.3
), and these are called 'stable' versions. Other versions have an interim name or number(e.g. v1.2.alpha1
or dev-master
) indicating that additional testing is appropriate.
As a general rule, a new composer
deployment will (and should) only use 'stable' versions. CiviCRM, too, isgenerally built around 'stable' dependencies. However, in some exceptional cases, CiviCRM requires an interimrelease of some libraries.
composer.json
has two options which affect this: minimum-stability sets anabsolute baseline, and prefer-stable expresses a general preference.Setting minimum-stability
to dev
enables to installation to proceed when there are exceptional cases. Settingprefer-stable
to true
means that composer
will use stable releases whenever it can.
When you first install or upgrade to CiviCRM 5.31+, composer
will prompt for permission to run CiviCRM compilation tasks. We recommend that you select [a]lways
.
If you wish to suppress the prompt, see Composer Compile Plugin: Managing the root package (for site-builders).

Package | Description |
---|---|
civicrm/civicrm-asset-plugin | A tool which automatically copies JS+CSS assets from CiviCRM to D8/D9's web/ folder |
civicrm/civicrm-core | The primary CiviCRM codebase |
civicrm/civicrm-drupal-8 | The integration module for CiviCRM and D8/D9 |
civicrm/civicrm-packages | A collection of third-party/legacy packages used by CiviCRM |
The primary CiviCRM packages (civicrm-core
, civicrm-drupal-8
, civicrm-packages
) have synchronizedversions. If one package is installed with v5.35, then the others should also be v5.35.
The following expression references the three packages and applies the same version-constraint to each:
The expression ~5.35
is a version-constraint. It means that composer will install approximately v5.35
. It mayinstall a newer patch-release (e.g. 5.35.1
) or a newer minor-release (e.g. 5.36.0
). However, it will avoidmajor-releases (e.g. 6.0.0
).
Many composer
tutorials rely on composer
to automatically choose package-versions.This is not recommended for CiviCRM and Drupal 8/9. Instead, package versioning should be explicit to ensure that:
- CiviCRM versions remain synchronized.
- CiviCRM stable releases are preferred over developmental releases.
pear/exception
?In some D8 configurations, you may see an error message about the package pear/exception
. This isbecause some packages use pear/exception
-- but they have been overly specific about the requiredversion. (To wit: they require version 1.0.0
when version 1.0.1
will also work.)
To resolve this error, you can install v1.0.1 and pretend that it is v1.0.0:
After fixing this, you may continue the regular installation commands.
Get the translations¶

I18n & L10n on Drupal 8 or 9
If installing with the GUI it is currently only possible to install CiviCRM in English (US) on Drupal 8/9. Adding the language files involves breaking with Composer best practices by writing the contents of the civicrm-l10n
tarball into vendor/civicrm/civicrm-core
or configuring the civicrm.l10n
directory path after you install and placing the contents of the civicrm-l10n
tarball into the configured directory.
Here Be Dragons...
The following steps are provided as an example - they are not supported or widely tested and may leave your site in a broken state. You use them at your own risk. No. Seriously...
You will also have to repeat these steps every time you upgrade CiviCRM.
The warnings above notwithstanding to install CiviCRM on Drupal 8/9 requires the following additional steps to prepare:
- Add
cv
to your Drupal 8/9 Site with:composer require civicrm/cv
(composer installs of cv are currently broken for now use the manual install steps.) Grab the localisation (l10n) files and unpack the
l10n
andsql
subfolders intovendor/civicrm/civicrm-core/
- You'll find the l10n files on the CiviCRM Download page or from
https://download.civicrm.org/civicrm-VERSION-l10n.tar.gz
whereVERSION
is a recent version of CiviCRM.
Example:
- You'll find the l10n files on the CiviCRM Download page or from
If you've done this correctly, you should end up with
vendor/civicrm/civicrm-core/l10n
andvendor/civicrm/civicrm-core/sql/
- You can remove any languages you don't need by deleting them before copying the
l10n
andsql
folders.
- You can remove any languages you don't need by deleting them before copying the
Now we move onto Installing CiviCRM - Command line install
Run the installer¶
The installer verifies requirements, prepares the database, and initializes the configuration file. You may run the installer through the web interface (which is simpler) or the command-line interface (which has more options).
Currently there is no interactive installer for CiviCRM on Drupal 8/9, so the installer uses a firm set of defaults, e.g.
- English Language Data: It only installs data for US English. It cannot install data for other languages.
- Shared Database: It only uses the shared CMS database. It cannot use a separate MySQL database for CiviCRM.
- No Sample Data: It only installs an empty, baseline dataset. It cannot install sample data.
If you need to configure any of these options, then use the command-line installer.
It is critical that your web-server user is able to write to the web/sites/default/
directory in order to create civicrm.settings.php
and that you have an appropriate value for execution time(s) and memory limit(s) as any interruption to the installer can (and will) result in an unusable install and require remedial steps to correct or a full reinstall! By default on Drupal 8.8+ this directory path is not writable by default, before installing you should ensure you grant write access to your web server user. With, e.g: sudo chmod u+w web/sites/default
.
For multisite installations you'll also need to ensure your web server user has write access to additional sites e.g: sudo chmod u+w web/sites/site2.example.org
.
- Login to your Drupal site with administrator permissions.
Navigate to Manage >> Extend or point your web browser to the following URL:
https://example.org/admin/modules/
Find 'CiviCRM Core' and enable it (you can optionally enable 'CiviCRM Theme' to set a theme just for CiviCRM.)
- At the bottom, click 'Install'. (Note: This may take a few moments to execute.)
CiviCRM has a command-line administration tool, cv
, which can perform installation. For details, see command-line installer.

Civicrm Drupal 9 Release
Review the permissions¶
Drupal will create the /files/
directory (and make it writeable), but only when saving admin/settings
. Same holds for /temp
directory, and a /uploads/
directory in the CiviCRM module root. On a brand-new Drupal install, this directory may be missing. Even on an existing installation, if file permissions are not set properly, the directory may be missing. If enabling the CiviCRM module generates errors regarding the files directory, you must create it (writeable) manually.
Go to the CiviCRM dashboard to see the CiviCRM menus:
https://example.org/civicrm
(orhttps://example.org/index.php?q=civicrm
if you don't have Clean URLs enabled)Go to Administer » User management » Permissions
Verify that the Roles that you want to have access to CiviCRM have the appropriate permissions checked. CiviCRM is installed with a number of fixed permissions (such as 'edit contacts' and 'administer CiviCRM').
Permissions for the Anonymous Role
Many sites want anonymous visitors to have access to certain CiviCRM functionality. These permissions are enabled during installation for the Anonymous role. You should review them and modify if needed based on your requirements:
- access all custom data : If you plan on collecting 'custom' data from visitors in standalone forms or as they make a contribution - enable this permission.
- access CiviMail subscribe/unsubscribe pages : If you are planning on using CiviMail, enable this permission to allow anonymous users to subscribe and unsubscribe from mailing lists via the web.
- access uploaded files : If you plan on allowing visitors to upload or view photos or other files - enable this permission.
- make online contributions : If you plan on soliciting online contributions from visitors, enable this permission for the 'anonymous' role.
- profile listings and forms : If you plan on collecting name and address or other information from visitors, enable this permission for the 'anonymous' role.
- view event info and register for events : If you plan to use CiviEvent and want to allow un-authenticated visitors to view event information and register for events online - enable these permissions for the 'anonymous' role.
- view event participants : Enable this permission to allow anonymous users to access participant listing pages for events.
Synchronize the users¶
Once installed, CiviCRM keeps your Drupal Users synchronized with corresponding CiviCRM contact records. The 'rule' is that there will be a matched contact record for each Drupal user record. Conversely, only contacts who are authenticated users of your site will have corresponding Drupal user records.
When CiviCRM is installed on top of an existing Drupal site, a special CiviCRM Administrative feature allows you to automatically create CiviCRM contacts for all existing Drupal users:
- Login to your Drupal site with an administrator-level login
- Click the CiviCRM link in the main navigation block
- If your Drupal site makes use of the
db_prefix
setting (insettings.php
), in the top bar click Administer » System Settings » CMS Database Integration , and update the box for the Drupal Users Table Name so that it includes the prefix. - Click Administer in the menu bar
- Click Users and Permissions from the drop-down menu, then select Synchronize Users to Contacts
Review the checklist¶
The Configuration Checklist provides a convenient way to work through the settings that need to be reviewed and configured for a new site. You can link to this checklist from the installation success page and you can visit it at any time from Administer » Administration Console » Configuration Checklist.
Test-drive CiviCRM¶
There should now be a CiviCRM link in your Drupal menu. Click that link and the CiviCRM Menu, Shortcuts, Search and New Individual Blocks should appear. You can now explore CiviCRM end-user features and begin configuring CiviCRM for your site/organization needs.
Addenda¶
TLS for MySQL¶
If your MySQL database is hosted on a different machine than your web server, or if your host requires it, you can use TLS to encrypt the connection between the database and the web server.
Full instructions on installing drupal are out of scope for this guide, but one method is to install into a test database first without MySQL encryption and then move the database to the live server and update settings.php to enable MySQL encryption.
See TLS for MySQL for introductory concepts and the settings for the CiviCRM database. For the Drupal database you have several options for updating settings.php:
The simplest, which doesn't require a client certificate, but doesn't verify the server certificate.
Verifies the server certificate, and doesn't require a client certificate.
Host name must match certificate name
Note that the DATABASE SERVER certificate would have to have a CN (common name field) that matches exactly the
host
you are using in$databases['default']['default']['host']
. So if the host isdb435.examplehost.com
, then that must be the name on the SERVER certificate.Client certificate/key pair (not self-signed), and do not verify the server certificate.
Client certificate/key pair (could be self-signed), and verify the server certificate.
Integration modules¶
Webform CiviCRM module
CiviCRM Entity module
Troubleshooting¶
- Review the Troubleshooting page for help with problems you may encounter during the installation.
CiviCRM is a community-based open source project to build constituent relationship management functionality for the nonprofit, advocacy and nongovernmental sectors.
You can use this demo site to try out most of the features of CiviCRM including online donation processing, event management, memberships, case management, reporting and more ...
Just login with...
Username: demo
Password: demo
... and click the CiviCRM link (upper left-hand corner of your screen)
Any data you enter on this demo site is 'publicly available' due to the open login. Please do not enter real email addresses or other personal information. The demo database is reset periodically.
Civicrm Drupal 8
New to CiviCRM?
Civicrm Drupal 9 Download
- Learn about how you can use CiviCRM from our new online book.
- Check out CiviCRM.org for an overview of the project, blogs, professional services listings and other resources and links.
- Join the Mattermost chat to see what folks in the CiviCRM community are talking about.