How to Test a WordPress Migration on a VPS Before Switching DNS

A WordPress migration looks done the moment the files and the database land on the new VPS. It is not. Until you test WordPress migration before switching DNS, you have no idea whether the site actually works on the new server. DNS is the switch that sends real visitors to the new server, and once you flip it, every broken link, missing upload, and wrong database value becomes public. Testing first takes an hour or less.

WordPress migration testing means loading the copied site on the new server while the old site still serves visitors. Check the pages, the admin area, the forms, and the database, fix what is broken, and only then point the domain at the new VPS.

Test WordPress migration before switching DNS with your hosts file

The hosts file method is the closest thing to a real test. It tells your own computer to load your domain from the new VPS, while everyone else still reaches the old host.

Find the public IP address of your VPS, then add one line to the hosts file on your computer:

203.0.113.10 example.com www.example.com

Replace 203.0.113.10 with your VPS IP and example.com with your real domain. The hosts file lives in a different place on each system:

  • Linux and macOS: /etc/hosts, edited with sudo.
  • Windows: C:WindowsSystem32driversetchosts, edited as Administrator.

After saving, flush your local DNS cache so the new entry takes effect:

# Linux (systemd-resolved)
sudo systemd-resolve --flush-caches

# macOS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

# Windows (Command Prompt as Administrator)
ipconfig /flushdns

Now open your domain in the browser. You are looking at the copy on the new VPS, even though the address bar shows the normal domain. Log in to wp-admin, open several pages, and submit a form. When you finish testing, delete the line from the hosts file and flush the cache again.

Expect a certificate warning. A hosts file entry does not change public DNS, so a certificate authority cannot verify your domain against the new server yet. If the new VPS has no valid certificate, your browser will warn you. That is normal at this stage. Click through the warning for testing, or issue the certificate with DNS validation. Sort out HTTPS before the DNS switch, not after.

Use a staging subdomain on the new VPS

A staging subdomain gives you a separate address for the copied site, such as staging.example.com. Point that subdomain at the VPS, copy the site there, and test it without touching the live domain. This works well when several people need to review the migration, or when you cannot edit the hosts file on every device.

Create the subdomain in your DNS panel and point its A record at the VPS IP. Create a matching server block in Nginx, copy the WordPress files and database, and update the site URL. If you have not set up a staging site before, our guide to setting up a WordPress staging site on a VPS subdomain walks through the Nginx and database steps in detail.

A staging subdomain also makes it easy to clone a WordPress site for testing without touching the live one. You can break things, fix them, and test again while the production site keeps running.

The one trap with a staging subdomain is the URL. WordPress stores the site address in the database, and many links and image paths include it. If you copy the database and forget to change the URL, the staging copy will redirect you to the live domain, or load images from the old server. Always run a search and replace on the staging copy, and test in a private browser window so cached redirects do not fool you.

Search and replace the old URL in the database safely

Almost every WordPress migration involves a URL change: from http to https, from a staging address to the live domain, or from the old host to the new one. WordPress stores URLs in post content, widget settings, theme options, and plugin settings. A plain SQL REPLACE breaks serialized data, because serialized strings store their own length. Change a URL, the length changes, and the stored value becomes unreadable.

Use WP-CLI instead. It handles serialized data correctly, and the --dry-run flag shows you what would change before anything is written:

# Preview the changes first, no writes
wp search-replace 'https://staging.example.com' 'https://example.com' --all-tables --dry-run

# Run it for real once the preview looks right
wp search-replace 'https://staging.example.com' 'https://example.com' --all-tables --precise

Run WP-CLI from the WordPress root directory on the VPS, with the user that owns the files. Add --skip-columns=guid to leave post GUIDs alone, since those are meant to stay permanent.

Migration plugins such as WP Migrate, All-in-One WP Migration, and Duplicator handle the search and replace step during the move. If you are still choosing one, our comparison of WP Migrate vs All-in-One WP Migration vs Duplicator covers the limits of each. Back up the database on the new VPS before running the replace, so a bad replace is a restore, not a rebuild. The same habit applies everywhere: test your VPS backup by restoring it before you actually need it.

Pre-launch checklist: what to check before you flip DNS

Run through this list on the copied site while the old site still serves visitors.

Check What to look for
Homepage and key pages Pages load with a 200 status, no missing styles
wp-admin login Login works, dashboard loads without errors
Permalinks Post and page URLs work, no 404s
Media library Images load from the new server, not the old one
Forms and checkout Forms submit, WooCommerce checkout completes on a test order
Search and replace No old domain or staging URL left in page source or database
HTTPS Valid certificate, no mixed content warnings
WordPress cron Scheduled posts and plugin tasks run
Email sending Password resets and form notifications arrive
Error log No PHP fatal errors in the Nginx or PHP-FPM log
PHP version Same PHP version as the old host

Check the error log after clicking through the site. Many problems only appear when a specific page or plugin runs:

sudo tail -n 100 /var/log/nginx/example.com.error.log
sudo tail -n 100 /var/log/php8.3-fpm.log

If the log is clean after a full click-through, the migration is in good shape.

Common problems and how to fix them

Redirect loop. The site bounces between http and https, or between www and non-www. Check the site URL in wp_options and the Nginx server block. Both must agree on one canonical address. Clear the cache after changing the URL.

White screen or 500 error. A PHP fatal error, usually from a plugin that needs a different PHP version or a missing extension. Read the PHP-FPM error log first; it names the file and the line. Deactivate plugins from WP-CLI with wp plugin deactivate --all and reactivate them in groups to find the culprit.

Database connection error. WordPress cannot reach MySQL. Check the database name, user, password, and host in wp-config.php, and confirm the MySQL user has rights on the new database. A wrong table prefix in wp-config.php causes the same message on a fresh import.

404 errors on posts but the homepage works. Permalinks are not saved. Go to Settings, then Permalinks in wp-admin and save the settings again. If it still fails, check that the Nginx configuration passes the request to WordPress instead of serving a static file.

Images load from the old server. The search and replace missed some URLs, often in theme options or page builder data. Run wp search-replace again with --all-tables and check the page source for the old domain. Hardcoded URLs in theme files need a manual edit.

When it is safe to switch DNS

Switch DNS only after every checklist item passes and the error log stays clean. Before you change the records, lower the TTL on the domain to 300 seconds, at least 24 hours ahead of time. A low TTL means visitors pick up the new address within minutes if you need to roll back.

If you followed our guide on how to migrate WordPress from shared hosting to a VPS, the DNS step is the same: update the A record to the VPS IP, then check the site from two or three networks to confirm the change has spread. Keep the old hosting account alive for at least 48 hours. If something breaks after the flip, you can point DNS back while you fix the new server.

Testing a WordPress migration before switching DNS is not extra work. It is the work. The copy, the database import, and the file transfer are the easy parts. Proving the site works on the new VPS, while visitors still use the old one, is what makes a migration boring.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.