Drupal & CiviCRM
Local Development (DDEV)
Pre-steps
New Git repo:
- Initialize new repo.
- Take care that repo directory is empty, only .git should be there.
- Run:
ddev config --project-type=drupal11 --docroot=public_html --php-version=8.3 ddev start touch dummy.sql ddev import-db --database crm --file dummy.sql rm dummy.sql ddev composer create drupal/recommended-project:^11 --no-install --no-interaction sed -i 's/web\//public_html\//' composer.json ddev composer config --no-interaction extra.enable-patching true ddev composer config --no-interaction extra.compile-mode all ddev composer config --no-plugins --no-interaction allow-plugins.cweagans/composer-patches true ddev composer config --no-plugins --no-interaction allow-plugins.civicrm/civicrm-asset-plugin true ddev composer config --no-plugins --no-interaction allow-plugins.civicrm/composer-downloads-plugin true ddev composer config --no-plugins --no-interaction allow-plugins.civicrm/composer-compile-plugin true ddev composer require --no-interaction civicrm/civicrm-{core,packages,drupal-8} ddev composer require --no-interaction civicrm/cli-tools ddev composer require --no-interaction drush/drush mkdir -p public_html/libraries ln -s ../../libraries/civicrm/ public_html/libraries/civicrm ddev composer install --no-interaction ddev drush site:install --account-name=admin --account-pass=admin --locale=nl -y ddev drush config:get system.site uuid | awk '{print $2}' | head -1 > site.id # Obtaining site.id for publishing site config to tst/prd ddev describe -j | jq .raw.httpsurl | sed 's/"//g' > site.url # Obtaining site.url for installing CiviCRM sed -i "s/# \$settings\['config_sync_directory'\] = '\/directory\/outside\/webroot';/\$settings\['config_sync_directory'\] = '..\/config\/sync';/" public_html/sites/default/settings.php ddev exec 'export CIVICRM_L10N_BASEDIR=$PWD/public_html/sites/default/files/civicrm \ && export CMS_URL=$(cat site.url) \ && cd public_html \ && cv core:install --url=$CMS_URL --db="mysql://db:db@db:3306/crm" --lang="nl_NL" -m loadGenerated=1 -f' ddev drush config:export ddev launch $(ddev drush uli) - When the website is launched, change the password if deemed necessary
- Add .gitignore with:
.ddev/ public_html/ recipes/ vendor/ libraries/
Existing Repo:
- Clone the repo
- Verify composer.json (web root = pubclic_html)
- Run:
ddev config --project-type=drupal11 --docroot=public_html --php-version=8.3 ddev start touch dummy.sql ddev import-db --database crm --file dummy.sql rm dummy.sql ddev composer config --no-interaction extra.enable-patching true ddev composer config --no-interaction extra.compile-mode all ddev composer config --no-plugins --no-interaction allow-plugins.cweagans/composer-patches true ddev composer config --no-plugins --no-interaction allow-plugins.civicrm/civicrm-asset-plugin true ddev composer config --no-plugins --no-interaction allow-plugins.civicrm/composer-downloads-plugin true ddev composer config --no-plugins --no-interaction allow-plugins.civicrm/composer-compile-plugin true ddev composer require --no-interaction civicrm/civicrm-{core,packages,drupal-8} ddev composer require --no-interaction civicrm/cli-tools ddev composer require --no-interaction drush/drush mkdir -p public_html/libraries ln -s ../../libraries/civicrm/ public_html/libraries/civicrm ddev composer install --no-interaction ddev drush site:install --account-name=admin --account-pass=admin --locale=nl -y ddev describe -j | jq .raw.httpsurl | sed 's/"//g' > site.url # Obtaining site.url for installing CiviCRM sed -i "s/# \$settings\['config_sync_directory'\] = '\/directory\/outside\/webroot';/\$settings\['config_sync_directory'\] = '..\/config\/sync';/" public_html/sites/default/settings.php ddev exec 'export CMS_URL=$(cat site.url) \ && cd public_html \ && cv core:install --url=$CMS_URL --db="mysql://db:db@db:3306/crm" --lang="nl_NL" -m loadGenerated=1 -f' set site_id $(cat site.id) ddev drush config:set system.site uuid $site_id -y sed -i "s/# \$settings\['config_sync_directory'\] = '\/directory\/outside\/webroot';/\$settings\['config_sync_directory'\] = '..\/config\/sync';/" public_html/sites/default/settings.php ddev drush config:delete shortcut.set.default -y set nl_uuid $(grep uuid config/sync/language.entity.nl.yml | awk '{print $2}') ddev drush config:set language.entity.nl uuid $nl_uuid -y ddev drush config:import -y ddev launch $(ddev drush uli)
Updating
ddev composer update
cd ./public_html
ddev drush updatedb
ddev drush cr
# If CiviCRM had update
curl -Lss -o public_html/sites/default/files/civicrm/l10n/nl_NL/LC_MESSAGES/civicrm.mo https://download.civicrm.org/civicrm-l10n-core/mo/nl_NL/civicrm.mo
ddev exec 'export CIVICRM_SETTINGS=$(find -name civicrm.settings.php) && cv upgrade:db'
rm -rf public_html/sites/default/files/civicrm/templates_c/
ddev exec 'export CIVICRM_SETTINGS=$(find -name civicrm.settings.php) && cv flush'
ddev composer civicrm:publish
Patching
composer require cweagans/composer-patches
"enable-patching": true,
"patches": {
"drupal/core": {
"Change the LB Add block link text to understand in which region the block will be placed": "https://www.drupal.org/files/issues/2024-07-10/drupal-3460462-9.patch"
}
}
Installation on mijn.host hosting
Clone git repo first, then install Drupal, providing details manually to the installer.
composer install
./vendor/bin/drush site:install --locale="nl"
Make a note of the provided username and password.
Now export the crm user name and pass
set +o history
export CRM_DB_USER=
export CRM_DB_PASS=
Now install CiviCRM:
cms_url=$(pwd | awk -F "/" '{print $5}')
ln -s ../../libraries/civicrm public_html/libraries/civicrm
mkdir -p public_html/sites/default/files/civicrm/l10n/nl_NL/LC_MESSAGES
curl -Lss -o public_html/sites/default/files/civicrm/l10n/nl_NL/LC_MESSAGES/civicrm.mo https://download.civicrm.org/civicrm-l10n-core/mo/nl_NL/civicrm.mo
cd public_html
chmod +w sites/default/
set +o history
../vendor/bin/cv core:install --url="https://${cms_url}" --db="mysql://${CRM_DB_USER}:${CRM_DB_PASS}@localhost:3306/${CRM_DB_USER}" --lang="nl_NL"
Answer any question that pops up (e.g. db already populated) and run these commands to finish civicrm installation
set -o history
chmod -w sites/default/
cd ..
./vendor/bin/drush cr
Now some manual work:
WIth vi open settings.php file:
vi public_html/sites/default/settings.php
Edit the last row and change the provided path to ../config/sync
#E.g. change:
$settings['config_sync_directory'] = 'sites/default/files/config_7Mlw0xeTGW_fmBMDS-RmPr29yA3WsBBqcdHxMO_BE1S9DRichbda04ZmUQeV_yJD0tRu4Rk_dA/sync';
#into:
$settings['config_sync_directory'] = '../config/sync';
When done, load the site config with the following commands
site_id=$(cat site.id)
./vendor/bin/drush config:set system.site uuid $site_id -y
./vendor/bin/drush config:delete shortcut.set.default -y
nl_uuid=$(grep uuid ./config/sync/language.entity.nl.yml | awk '{print $2}')
./vendor/bin/drush config:set language.entity.nl uuid $nl_uuid -y
./vendor/bin/drush config:import -y
Updating on mijn.host hosting
composer install --no-dev
cd ./public_html
export SITE_URL=$(cat ../site.url)
../vendor/bin/drush -l $SITE_URL updatedb
../vendor/bin/drush cr
# If CiviCRM had update
curl -Lss -o sites/default/files/civicrm/l10n/nl_NL/LC_MESSAGES/civicrm.mo https://download.civicrm.org/civicrm-l10n-core/mo/nl_NL/civicrm.mo
../vendor/bin/cv upgrade:db
rm -rf sites/default/files/civicrm/templates_c/
../vendor/bin/cv flush # Ignore the error
composer civicrm:publish