update urls in database after importing to local to solve redirection issues

Am setting up a local development environment for WordPress, using VVV vagrant. I already exported the original database from production and imported it in the local placeholder website.

  • Don’t modify the production database.
  • Only modify the local database.

For single-site installs, just replace the “siteurl” value in the “wp-options” from http://www.liveproductionsite.com to http://localtestsite.test

For multisite-installs, there are a few more hoops to jump through.

Remember: this impacts redirections. Your browser tends to remember these in its cache. Whenever you try something, make sure you clear all history so that past redirections won’t be remembered by the browser.

The tables you need to replace urls in for wordpress multisite on local are :

  • wp_domain_mapping
  • wp_sitemeta
  • wp_blogs
  • wp_options
  • wp_2_options, wp_3_options…
  • wp_site

And the fields to replace are:

  • siteurl
  • home
  • (possibly) vhp_varnish_url

Update siteurl in wp_domain_mapping

  • in the “wp_domain_mapping” table, replace the “domain” value from the live production values to the local test values. For instance: domain1.liveproductionsite.com to domain1.localtestsite.test

This will:

  • adjust/reset the main URL for the sites included to the local environment.
  • updates links that are automatically generated by the wordpress theme such as category menus and internal linking.
  • Also, it enables you to log into the back office (using your production wordpress logins).

What doesn’t work only with this:

  • images are still fetched from the original servers,
  • customized widgets and menu items still refer to outside locations.
  • Also, this doesn’t replace the network domain, which you can’t access at this stage