Home / Guides / WordPress handbook / Chapter 15
WordPress handbook · Chapter 15 · Maintenance
Migrations, Domain Changes and Staging
Moving a WordPress site combines most of the risks in this manual at once: files, database, serialized data, DNS, certificates, email, caches and third-party integrations. Migrations go wrong when they are treated as "copy the files and the database". This chapter treats them as a planned change with a checklist, a rollback path and a verification step.
On this page
Types of migration
| Scenario | What changes | Main risks |
|---|---|---|
| Host to host, same domain | Server, IPs, PHP/database versions, paths | DNS cut-over timing, email records, different server stack (Apache → Nginx), file ownership |
| Domain change | URLs everywhere in the database and files | Serialized data, SEO (redirects), email sender domains, licence activations, payment/webhook URLs |
| HTTP → HTTPS | Scheme | Mixed content, redirect loops, proxy detection |
| Subdirectory ↔ root, or www ↔ non-www | Paths or host name | Rewrite rules, cookies, canonical URLs |
| Production → staging (and back) | URL and environment | Staging sending email or charging customers; overwriting production data when pushing back |
| Single site → Multisite (or reverse) | Table structure and URLs | Complex; usually a specialist task |
Planning: before moving anything
- Inventory: WordPress, PHP and database versions; server type; caching layers; CDN; cron jobs; custom
.htaccess/Nginx rules; email provider; integrations and webhooks. - Check the destination supports the same (or newer, tested) PHP and database versions and required extensions.
- Export the full DNS zone from the current DNS host, including MX, TXT (SPF, DKIM, DMARC, verification) and CNAME records.
- Lower the TTL of the records you will change to 300 seconds, at least a full old-TTL period (often 24–48 hours) before cut-over.
- Take a complete backup (files and database) and confirm it restores.
- List everything that stores the site URL outside the database: payment gateway webhook URLs, OAuth redirect URIs (Google, Microsoft), API allowlists, CDN origin settings, licence activations.
- Decide the content freeze: for stores and membership sites, plan a short maintenance window so no orders are written to the old server after the database export.
- Prepare the rollback: keep the old server running unchanged until the new one is verified.
The migration procedure
- Copy files to the destination: the whole WordPress directory, including dotfiles (
.htaccess,.user.ini),wp-contentand any folders outside the web root the site uses (private uploads, config). Preferrsyncover SSH, or a migration plugin for hosts without shell access. - Export the database with a consistent dump (
wp db export --single-transaction) and import it at the destination into a new database with a new, scoped user. - Update
wp-config.phpwith the new database credentials and host. Keep the same keys and salts if you want users to stay logged in; change them if the move is also a security reset. - Fix ownership and permissions for the destination's PHP user.
- Server configuration: recreate custom rules. Moving from Apache to Nginx means translating
.htaccessrules into the server block (Chapter 07). - Preview before DNS: test the new server with a hosts-file entry or
curl --resolve, so you see the new site under the real domain while the world still sees the old one. - Search-replace only if the URL changes (next section).
- Certificates: issue the certificate on the new server. HTTP-01 validation only works once DNS points there; DNS-01 validation, or the host's pre-issuance tools, avoid a gap.
- Cut over DNS, and for stores enable maintenance mode on the old site during the final sync.
- Verify (checklist below), then keep the old server available for a few days before decommissioning it.
rsync -azP --delete -e ssh /var/www/example.com/public/ deploy@new-server:/var/www/example.com/public/
curl -sI --resolve example.com:443:203.0.113.20 https://example.com/ # preview new server (203.0.113.20)
If the new server does not yet have a valid certificate for the domain, browsers will show a warning during preview. Accept it only for testing, or use the host's temporary URL feature where it handles URLs safely.
Changing URLs safely: search-replace
WordPress stores absolute URLs in posts, options, widgets, builder data and plugin settings, often inside serialized arrays. A safe URL change uses a tool that unserializes, replaces and reserializes, so stored string lengths stay correct:
wp db export before-replace.sql --single-transaction
wp search-replace 'https://old.example.com' 'https://new.example.com' --all-tables-with-prefix --skip-columns=guid --dry-run
wp search-replace 'https://old.example.com' 'https://new.example.com' --all-tables-with-prefix --skip-columns=guid --report-changed-only
# Catch protocol-relative and escaped forms used in JSON (block and builder data):
wp search-replace '//old.example.com' '//new.example.com' --all-tables-with-prefix --skip-columns=guid
wp search-replace 'https:\/\/old.example.com' 'https:\/\/new.example.com' --all-tables-with-prefix --skip-columns=guid
wp cache flush
--dry-runfirst, always, and read the counts per table.--skip-columns=guid: the GUID is an identifier, not a link. Changing it on a live site makes feed readers show old posts as new. On a brand-new site that was never public, changing it is harmless.- Page builders may cache generated CSS containing old URLs; regenerate their CSS afterwards (Elementor's Replace URL and Regenerate CSS tools, Divi's static CSS clear, and similar).
- Hard-coded URLs in theme files, custom CSS and JavaScript are not in the database; search the files too.
- Never use a plain SQL
UPDATE ... REPLACE()across options and meta; it corrupts serialized data (Chapter 08).
Email and DNS during a migration
Email is the casualty in most migrations:
- Changing nameservers moves every record. Recreate MX, SPF, DKIM, DMARC and autodiscover records at the new DNS host before switching nameservers.
- If email was hosted with the old web host, moving web hosting may also move or end email hosting. Decide where mailboxes live and migrate them separately.
- The new server's IP must be in SPF if WordPress sends mail directly. Better: send via an authenticated provider so the server IP is irrelevant (Chapter 16).
- After cut-over, send test emails from WordPress (password reset, form, order) and check SPF/DKIM/DMARC results in the received headers.
Domain changes and SEO
- Map every old URL to its new URL (usually the same path on the new domain).
- Implement 301 redirects at the server or CDN on the old domain: host-level, path-preserving, single hop.
- Update canonical URLs, sitemaps and hreflang through the SEO plugin (search-replace usually handles these).
- Verify the new domain in Search Console and use the Change of Address tool from the old property.
- Keep the old domain registered and redirecting for at least a year; letting it lapse invites domain squatters who inherit your backlinks.
- Update profiles, ad accounts, analytics settings, email signatures and payment-provider settings.
Staging environments done safely
- Block indexing with HTTP authentication (more reliable than robots.txt alone) and Settings → Reading → Discourage search engines.
- Mark the environment:
define( 'WP_ENVIRONMENT_TYPE', 'staging' );. Many plugins disable live integrations when they see it. - Stop email: route all mail to a catch-all testing inbox, or disable sending.
- Stop payments and renewals: switch gateways to test mode; heed WooCommerce Subscriptions' duplicate-site prompt.
- Stop syncs: ERP, CRM, marketplaces, newsletter lists and webhooks.
- Protect data: staging contains real personal data; restrict access, and consider anonymising customers in long-lived staging copies.
- Pushing back: push files freely; push the database only when production has not changed since the copy, or the store loses orders made in between. Prefer re-applying configuration changes manually on production for live stores.
Post-migration verification checklist
- DNS resolves to the new server from several networks (
dig, online DNS checkers). - HTTPS valid on all host names (apex and www); HTTP redirects to HTTPS in one hop.
- Home, posts, pages, archives, search and 404 behave correctly; permalinks work.
- wp-admin login works; no mixed-content warnings in the console.
- Media loads; uploads of new files work (permissions).
- Forms submit and emails arrive with SPF/DKIM/DMARC passing.
- Checkout completes in test mode; webhooks reach the new server.
- Caches (plugin, server, CDN) purged and working on the new server; logged-in and cart pages bypass cache.
- WP-Cron or the system cron runs on the new server; old server's cron disabled.
- Error logs on the new server are clean after browsing key pages.
- Backups configured and running on the new server.
- Security: PHP blocked in uploads, sensitive files denied (Chapter 07 tests).
- Search Console, analytics and uptime monitoring confirmed.
- Migration archives, installer files and database dumps removed from the web root.
Rather have someone else keep WordPress healthy?
Our managed hosting and care plans cover updates, backups, security monitoring and fixes like the ones in this handbook, so you can get on with running the business.
See Hosting & Care