Many of the steps documented on the "Migrating a site" wiki page are handled automatically now. Here's my recipe, which is far from perfect, but is much closer.
- Copy the entire filesystem to the staging server. Git works well for this, but when it's not an option, we'll use SFTP or create a tarball.
- Dump the database using
mysqldump, either directly or using
drush civicrm-sql-dump or
wp-cli cv sql-dump. Copy the db dump to the staging server. We don't use git for this because of the database size; we either use
drush sql-sync or copy it manually.
- Assuming a manual database dump copy, we need to remove the trigger definers - unless the MySQL username is identical on both production and staging. I use
sed -i -e 's:/\*\!50017.*\*/::g'.
- Load the database into MySQL on the staging server.
Assuming this is not the first time we set up the server, we're done! On first time setup, there are a few other things we need to do:
- Replace all the usernames, passwords, paths, etc. in
wp-config.php with the values appropriate to the staging server. If using git, these files are ignored in git, only local copies exist.
- There are a number of values we override in
civicrm.settings.php on the staging server to use the appropriate paths. Here's what I put in mine, directly below the
$civicrm_setting['CiviCRM Preferences']['allowPermDeleteFinancial'] = 1;
$civicrm_setting['Directory Preferences']['customTemplateDir'] = '/home/jon/local/example/wp-content/civicrm/templates';
$civicrm_setting['Directory Preferences']['customPHPPathDir'] = '/home/jon/local/example/wp-content/civicrm';
$civicrm_setting['Directory Preferences']['extensionsDir'] = '/home/jon/local/example/wp-content/civicrm/extensions';
$civicrm_setting['URL Preferences']['extensionsURL'] = 'http://example.local/civicrm/extensions/';
$civicrm_setting['URL Preferences']['imageUploadURL'] = 'http://example.local/wp-content/plugins/files/civicrm/persist/contribute/';
$civicrm_setting['URL Preferences']['userFrameworkResourceURL'] = 'http://example.local/wp-content/plugins/civicrm/civicrm';
In Wordpress, we also need to add a few overrides to
wp-config.php. Some of these may be overkill but:
Finally, if this is a multi-site Wordpress, we need to do a search and replace of the database for the URL. We do this with
wp-cli search-replace https://oldsite.com https://newsite.com but this tool also does the trick.