How Can We Help?
This is simply a set of personal notes based on the instructions at https://docs.civicrm.org/sysadmin/en/latest/misc/switch-servers/. I’ve trimmed it down to a bare bones walk-though for my WordPress situation and to include some solutions for ‘gotchas’ I ran into as I went. It assumes you’re pretty familiar with various command line tools and the Linux CLI in general. There are probably ‘better’ or more efficient ways to do this. I was trying to be very methodical and give myself as many recovery points as possible to avoid having to start over from the beginning.
- Create two new databases. One for WP and a separate one for CiviCRM. I used the same user for both, but it might be better to use different users. You don’t have to separate your CMS and CRM databases, but I am increasingly of the opinion that the minor inconvenience of separating them at the start makes for easier maintenance down the road, especially if/when you have to move or attempt repair.
- Set up the new WordPress server. In this case I used a new subdomain, but that may not be desirable. If re-using a subdomain, you’ll have to play some more games with hosts files and maybe ssl certificates to smooth the process, or take the old one offline to avoid conflicts. Definitely solvable, but outside the scope of this document.
- create the web server directory and download the latest WordPress code. I used wp-cli to download the latest en-CA version: ‘
wp core download --locale=en_CA
‘ - create the appropriate vhosts file in
/etc/apache/sites-available
and symlink tosites-enabled
. - Run the WordPress web install to get the DB credentials set or do it manually in
wp-config.php
. - use ‘
certbot --apache -d site.name
‘ to get ssl running. Or you can copy certificates, keys and manually sort out your vhosts files if you are keeping the same domain. - You may wish to use a WP plugin like ‘Customizer import and export’ to migrate some look and feel items from the old site to the new one.
- create the web server directory and download the latest WordPress code. I used wp-cli to download the latest en-CA version: ‘
- Setup CiviCRM on the new server.
- Download the CiviCRM plugin for WordPress. Do not simply use the latest CiviCRM, download the version that matches your existing database. E.g. ‘
wget https://download.civicrm.org/civicrm-VERSION-wordpress.zip
‘ - Optionally, download the matching localisation files if your CiviCRM install is multilingual.
'wget https://download.civicrm.org/civicrm-VERSION-l10n.tar.gz'
. - Unzip civicrm-VERSION-wordpress.zip to the WP plugins directory (and localisation files in plugins/civicrm)
- Activate CiviCRM from the WP plugins page.
- When answering the questions on the CiviCRM setup, read carefully and provide the database credentials for the CiviCRM database to ensure it doesn’t get mixed with WP.
- Review the settings from the old site, but DO NOT migrate the
file. You may need to transfer a value or two, but don’t bring the whole thing over. Sometimes I don’t need to copy anything.civicrm.settings.php
- Add CiviCRM modules and extensions to match the old database.
- Confirm the the new site is behaving well.
- Download the CiviCRM plugin for WordPress. Do not simply use the latest CiviCRM, download the version that matches your existing database. E.g. ‘
- Make code and database backups of this new server. This ensures we can get back to this ‘clean’ state if things go sideways.
- Clean the old database to prepare for import
- Export the database of the old CiviCRM installation using
'mysqldump
--skip-triggers'
(CiviCRM will rebuild triggers, which is preferable to having to clean up triggers that don’t work because of new locations, etc.) - Create a temporary database for cleaning the old database.
- Tweak the dumpfile you are about to import and clean. In spite of my note above and below about
--skip-triggers
I discovered a problem during the dump of the cleaned data below. I was getting ‘DEFINER’ errors because that was attached to some views in the dump file. Maybe these can be removed and rebuilt somehow, but I decided to do a search and replace before the import in the next step so that the old username that was listed as the DEFINER was replaced by the new username. I foolishly used vim this time, but my dumpfile was very large and it was annoying. Better to use sed next time:sed -i 's/Old_Username/NEWUSER/g' dumpfile.sql > NEWUSER_dumpfile.sql
- Import the dump file into your temporary database.
- Drop extraneous tables from the temporary database.
- Some will always be worth deleting:
civicrm_db_name.civicrm_acl_cache, civicrm_db_name.civicrm_acl_contact_cache, civicrm_db_name.civicrm_cache,
civicrm_db_name.civicrm_domain,
civicrm_db_name.civicrm_group_contact_cache
- Others drops will be more discretionary. I deleted all the
'log_%'
tables. I also dropped tables that were clearly for modules and extensions that I had removed, but left crap in the database. I was presuming that these tables were part of my problem. However, this is a dangerous game, so be careful. Go slowly and consider each removal. Because this is a backup and not the live DB, it’s not disastrous, but could set you back several steps if you guess badly. Dropping large numbers of tables can be tedious as you can’t use a wildcard, but the following code will create a script that you can then feed back in to drop the tables. I used Adminer to do this, but it should work ok in the command-line client too.- SELECT CONCAT(‘DROP TABLE ‘, TABLE_SCHEMA, ‘.’, TABLE_NAME, ‘;’)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE ‘log_%’
AND TABLE_SCHEMA = ‘civicrm_db_name‘;
- SELECT CONCAT(‘DROP TABLE ‘, TABLE_SCHEMA, ‘.’, TABLE_NAME, ‘;’)
- Some will always be worth deleting:
- Export the database of the old CiviCRM installation using
- Dump this cleaned temporary database for importing into the new site database.
- Disable the CiviCRM plugin on the new site. The first migration I did, I didn’t do this and it turned out ok, but it makes sense.
- Import the cleaned sql dump file into your newly setup CiviCRM database:
'mysql -u mysql_username -p civicrm_db_name < civi_dump_file_name_of_your_choice.sql'
- Clear CiviCRM cache:
'rm -rf /var/www/civi.site/wordpress/wp-content/uploads/civicrm/templates_c/*'
- Re-enable the CiviCRM plugin.
- Use the following URLs in your browser to review and update directory paths and base URLs.
See CiviCRM Menu: Administer >> System Settings >> Cleanup Caches and Update Pathshttp://example.org/wp-admin/admin.php?page=CiviCRM&q=civicrm/admin/setting/updateConfigBackend&reset=1
- Review paths:
http://example.org/wp-admin/admin.php?page=CiviCRM&q=civicrm/admin/setting/path?reset=1
- Rebuild menus:
http://example.org/wp-admin/admin.php?page=CiviCRM&q=civicrm/menu/rebuild&reset=1
- Rebuild database triggers:
http://example.org/wp-admin/admin.php?page=CiviCRM&q=civicrm/menu/rebuild&reset=1&triggerRebuild=1
Working through this again myself with a CiviCRM install that is not working well anymore. Updating the notes as I go.
As this is the only page on my site that gets much traffic, I’m enabling comments here in case someone has something important to add and share with others.