ddev / ddev

Docker-based local PHP+Node.js web development environments
https://ddev.com
Apache License 2.0
2.77k stars 606 forks source link

Document CiviCRM: Installation, and import and configuration of database and template settings #5373

Closed gitressa closed 1 year ago

gitressa commented 1 year ago

This is not a request for help, but just to document how to restore a CiviCRM installation in DDEV, in case anyone ever needs this information, since I spent some time figuring out how to import the second database, which contains CiviCRM.

A dedicated page for setting up DDEV with CiviCRM would be great, and if and when it is created, this tip could get included.

After restoring the Drupal installation files and database, you can import the CiviCRM database with this command:

ddev import-db --database=cividb --file=cividb.sql

Note: The extra database cividb will not be included if you run ddev describe.

civicrm.settings.php

Comment out the server settings, and use these values in your civicrm.settings.php file, inserted right after global $civicrm_root; if you want to keep them in one place:

global $civicrm_root;

/* LOCAL DEVELOPMENT */
define( 'CIVICRM_UF_DSN'  , 'mysql://db:db@db:3306/cividb?new_link=true' );
define( 'CIVICRM_DSN'     , 'mysql://db:db@db:3306/cividb?new_link=true' );
define('CIVICRM_LOGGING_DSN', CIVICRM_DSN);
$civicrm_root = '/var/www/html/sites/all/modules/civicrm';
define( 'CIVICRM_TEMPLATE_COMPILEDIR', '/var/www/html/sites/default/files/civicrm/templates_c/' );
define( 'CIVICRM_UF_BASEURL'      , 'https://civicrm.ddev.site/' );
gitressa commented 1 year ago

Closing, since there is nothing to fix.

rfay commented 1 year ago

Thanks for this. There are a couple of ways you might make this more accessible.

Anyway, thanks for capturing it!

gitressa commented 1 year ago

You're welcome @rfay, thanks for a fast answer!

An add-on could be an idea, though the install process is fairly "hand held" ...

https://docs.civicrm.org/installation/en/latest/drupal/

Maybe adding a recipe with just a README like for example https://github.com/ddev/ddev-contrib/tree/master/recipes/redaxo-cms could be worth considering?

gitressa commented 1 year ago

I created https://github.com/ddev/ddev-contrib/pull/235.

I have two questions and you probably know the answer :-)

rfay commented 1 year ago

The intl PHP extension is provided by default in DDEV.

Note: The extra database cividb will not be included if you run ddev describe.

I assume you're saying that ddev describe doesn't tell you about your extra databases. I never thought about that as being its job. It doesn't tell you about the mysql or information_schema or performance_schema databases. And of course all these things are different with PostgreSQL.

gitressa commented 1 year ago

Ah yes, you're right. I forgot to put ddev in front of the Composer command, so it was evaluating my machine PHP, not DDEV's. This works:

ddev composer require civicrm/civicrm-{core,packages,drupal-8}

Should I create a new merge request, or can you update the command in the documentation, and remove this bit? --ignore-platform-req=ext-intl

About the database, it's just because the default database is included:

$ ddev describe
┌───────────────────────────────────────────────────────────────────────────────────────────────┐
│ Project: civicrm ~/dev/civicrm https://civicrm.ddev.site                                      │
│ Docker platform: Ubuntu 20.04.6 LTS                                                           │
│ Router: traefik                                                                               │
├──────────┬──────┬────────────────────────────────────────────────────────┬────────────────────┤
│ SERVICE  │ STAT │ URL/PORT                                               │ INFO               │
├──────────┼──────┼────────────────────────────────────────────────────────┼────────────────────┤
│ web      │ OK   │ https://civicrm.ddev.site                              │ drupal10 PHP8.1    │
│          │      │ InDocker: web:80,8025,443                              │ nginx-fpm          │
│          │      │ Host: 127.0.0.1:32777,32778                            │ docroot:'web'      │
│          │      │                                                        │ NodeJS:18          │
├──────────┼──────┼────────────────────────────────────────────────────────┼────────────────────┤
│ db       │ OK   │ InDocker: db:3306                                      │ mariadb:10.4       │
│          │      │ Host: 127.0.0.1:32774                                  │ User/Pass: 'db/db' │
│          │      │                                                        │ or 'root/root'     │
├──────────┼──────┼────────────────────────────────────────────────────────┼────────────────────┤
│ Mailpit  │      │ Mailpit: https://civicrm.ddev.site:8026                │                    │
│          │      │ `ddev launch -m`                                       │                    │
├──────────┼──────┼────────────────────────────────────────────────────────┼────────────────────┤
│ All URLs │      │ https://civicrm.ddev.site, https://127.0.0.1:32777,    │                    │
│          │      │ http://civicrm.ddev.site, http://127.0.0.1:32778       │                    │
└──────────┴──────┴────────────────────────────────────────────────────────┴────────────────────┘

After importing the database, it's of course possible to verify via ddev ssh and mysql and show databases; and show tables;. But it would be nice if it was included, both to show the credentials, but also confirm it was created and working, like this:

$ ddev describe
┌───────────────────────────────────────────────────────────────────────────────────────────────┐
│ Project: civicrm ~/dev/civicrm https://civicrm.ddev.site                                      │
│ Docker platform: Ubuntu 20.04.6 LTS                                                           │
│ Router: traefik                                                                               │
├──────────┬──────┬────────────────────────────────────────────────────────┬────────────────────┤
│ SERVICE  │ STAT │ URL/PORT                                               │ INFO               │
├──────────┼──────┼────────────────────────────────────────────────────────┼────────────────────┤
│ web      │ OK   │ https://civicrm.ddev.site                              │ drupal10 PHP8.1    │
│          │      │ InDocker: web:80,8025,443                              │ nginx-fpm          │
│          │      │ Host: 127.0.0.1:32777,32778                            │ docroot:'web'      │
│          │      │                                                        │ NodeJS:18          │
├──────────┼──────┼────────────────────────────────────────────────────────┼────────────────────┤
│ db       │ OK   │ InDocker: db:3306                                      │ mariadb:10.4       │
│          │      │ Host: 127.0.0.1:32774                                  │ User/Pass: 'db/db' │
│          │      │                                                        │ or 'root/root'     │
├──────────┼──────┼────────────────────────────────────────────────────────┼────────────────────┤
│ cividb   │ OK   │ InDocker: db:3306                                      │ mariadb:10.4       │
│          │      │ Host: 127.0.0.1:32774                                  │ User/Pass: 'db/db' │
│          │      │                                                        │ or 'root/root'     │
├──────────┼──────┼────────────────────────────────────────────────────────┼────────────────────┤
[...]
gitressa commented 1 year ago

I created https://github.com/ddev/ddev-contrib/pull/236 to remove the redundant intl PHP extension note.

JoeMurray commented 1 month ago

Thanks, @gitressa for contributing back to the community like this. Just a note for people coming here and wanting to understand the state of play here, before possibly going further, in the following statements

define( 'CIVICRM_UF_DSN'  , 'mysql://db:db@db:3306/cividb?new_link=true' );
define( 'CIVICRM_DSN'     , 'mysql://db:db@db:3306/cividb?new_link=true' );

These two mysql connection strings define how CiviCRM will communicate with the User Framework, ie Drupal CMS database, in CIVICRM_UF_DSN and the CiviCRM database in CIVICRM_DSN. As configured, they indicate that Drupal and CiviCRM will share a single database named cividb. They also both use the same mysql username, db, which has a password also db, and a mysql server location of db communicating on the standard mysql port of 3306. Future work would be:

  1. Improve security by using a strong password.
  2. Slightly improve convenience of managing backups and restores by using a separate database for Drupal and CiviCRM.
  3. With separate databases, defining separate mysql users with their own strong passwords arguably would improve security a bit.

2 and 3 are perhaps bike-shedding, but 1 is important.