Project

General

Profile

Actions

Handling CiviCRM on dev/staging sites

Moving the CiviCRM database

CiviCRM database dumps contain DEFINER statements that specify a mysql user for the purpose of creating triggers. If the database is loaded from live with an incorrect user, the dev/staging site may not work correctly and backups will not run.

  • When syncing a civicrm database from its live server to a local or test server, the mysql user may be different. You can identify the mysql user for both in the database connection string in civicrm.settings.php:
    cat civicrm.settings.php | grep mysql
    
  • If the users in the two environments are different, before loading a dump from live you can replace the DEFINER `userlive`@`localhost` with `usertest`@`localhost` in the database dump file:
    sed -i 's/`userlive`@`localhost`/`usertest`@`localhost`/g' ~/sql-dump/example_civi.sql
    

You can also remove the DEFINER lines using. Although you want to save the original

$: sed 's/\sDEFINER=[^`]*`@`[^`]*//g' -i sql_dumpfile.sql 

Resource URL overrides

In development and staging environments, you can override CiviCRM options on dev/staging sites in civicrm.settings.php. Once overridden in this file, any resource URLs or other settings stored in the database will not disrupt the site when the database is synced from the live site.

Example settings for paths below. These lines may go at the top of civicrm.settings.php just under the opening PHP code tag, so they are obvious to other users.

global $civicrm_setting;
$civicrm_setting['Directory Preferences']['customTemplateDir'] = '/var/www/mysite/sites/all/civicrm/templates';
$civicrm_setting['Directory Preferences']['customPHPPathDir'] = '/var/www/mysite/sites/all/civicrm';
$civicrm_setting['Directory Preferences']['extensionsDir'] = '/var/www/mysite/sites/all/civicrm/extensions';
$civicrm_setting['URL Preferences']['extensionsURL'] = 'http://mysite.local/sites/all/civicrm/extensions/';
$civicrm_setting['URL Preferences']['imageUploadURL'] = 'http://mysite.local/sites/default/files/civicrm/persist/contribute/';
$civicrm_setting['URL Preferences']['userFrameworkResourceURL'] = 'http://mysite.local/sites/all/modules/contrib/civicrm';

It's also possible to override other values in the Setting object in this file to facilitate development or testing.

Updated by Manu Mei-Singh 9 months ago · 4 revisions

Also available in: PDF HTML TXT

Go to top