Tutorials

How to Test a Migrated Website on New Server Before Changing DNS (Hosts File Guide)

How to Test Migrated Site Before Changing DNS (Hosts File Guide) - CpanelFree Guide
Written by Blog

Quick Answer: To test a migrated website on a new server before changing public DNS records, add your new server IP and domain name to your local computer’s hosts file (e.g. 203.0.113.50 yourdomain.com www.yourdomain.com). This forces your computer to resolve the domain to the new server while all other global visitors continue browsing the old server without interruption.

Why You Should Never Update DNS Without Pre-Testing

Changing your domain nameservers or A record before testing is dangerous. If database credentials in wp-config.php have a typo, PHP versions are incompatible, or rewrite rules fail, your live visitors will experience broken layouts and 500 errors. Editing your local hosts file creates an isolated sandbox where you can test WooCommerce checkout, login sessions, and contact forms safely.

Step 1: Editing the Hosts File on Windows

  1. Press the Windows Key, type Notepad, right-click it, and select Run as administrator.
  2. In Notepad, click File > Open and browse to: C:\Windows\System32\drivers\etc\hosts (Select All Files (*.*) in the file type dropdown).
  3. Scroll to the bottom of the file and add your new server IP followed by your domain:
    203.0.113.50 yourdomain.com
    203.0.113.50 www.yourdomain.com
  4. Save the file and flush your DNS: ipconfig /flushdns.

Step 2: Editing the Hosts File on macOS / Linux

Open Terminal and edit the hosts file with sudo privileges:

sudo nano /etc/hosts

Add the line at the bottom, save (Ctrl + O, Enter), exit (Ctrl + X), and flush DNS cache:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Step 3: Alternative Browser Extension Method (Virtual Hosts)

If you don’t have administrator privileges on your computer, install the free Virtual-Hosts or LiveHosts extension for Google Chrome. Enter your new server IP and domain name to toggle between old and new servers with a single click.

Automating Hosts File Testing with Modern Browser Developer Tools

In addition to manual hosts file editing, web developers can use the curl command with the --resolve flag to test origin server response codes and SSL handshakes directly from the terminal:

# Test target IP directly presenting production domain headers
curl -Iv https://yourdomain.com --resolve yourdomain.com:443:203.0.113.50

Verify that the output returns HTTP/2 200 OK and that the SSL certificate subject name matches your domain.

Validating WooCommerce Checkout and Session Cookies

While testing via the local hosts file, perform a complete end-to-end transaction in test mode: add products to cart, proceed to checkout, verify payment gateway webhooks, and confirm transactional order receipt emails.

Comprehensive Hosts File Testing Checklist for Migrated Websites

  • Verify WordPress Admin Login: Log in to /wp-admin/ and ensure session cookies persist without redirection loops.
  • Test WooCommerce Checkout: Place a test transaction using Stripe/PayPal sandbox mode to verify SSL webhook communication.
  • Submit Contact Forms: Test contact forms and transactional email delivery to verify SMTP connectivity.
  • Check Media Uploads: Upload a new image in the Media Library to verify directory write permissions (chmod 755 wp-content/uploads).
  • Audit Console Errors: Open Chrome DevTools (F12) and inspect the Console tab for any mixed content warnings or 404 JavaScript errors.

Flushing Local DNS Resolver Caches Across Platforms

Operating System DNS Flush Command
Windows 11 / 10 ipconfig /flushdns
macOS (Sonoma / Ventura) sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Linux (systemd-resolved) sudo resolvectl flush-caches

Zero-Risk Website Migrations on CpanelFree

Test and deploy websites with 100% confidence. Enjoy free staging environments, cPanel management, and NVMe SSD hosting on CpanelFree.

Launch Free Staging Site

Frequently Asked Questions

Remember to remove the hosts file entry after testing!

Once you verify the new server and update your domain registrar’s DNS records, delete the custom IP line from your hosts file so your computer resumes standard DNS resolution.

Troubleshooting Hosts File Permissions and Antivirus Locks

On Windows, third-party antivirus suites (such as Windows Defender, Bitdefender, or Kaspersky) may lock the hosts file to prevent malware tampering. If Notepad reports Access Denied when saving, temporarily disable host file protection in your security suite or run PowerShell as Administrator to append the test record:

# Append test IP in Windows PowerShell (Administrator)
Add-Content -Path "C:\Windows\System32\drivers\etc\hosts" -Value "`n203.0.113.50 yourdomain.com`n203.0.113.50 www.yourdomain.com"

How do I know if my browser is loading the new server or old server?

Open Chrome DevTools (F12) > Network tab > click your domain request > look at Remote Address. It will display the IP address your browser is actively connected to.

Pro Sysadmin Tip: Testing SSL Handshake with OpenSSL CLI

Run openssl s_client -connect 203.0.113.50:443 -servername yourdomain.com to verify TLS cipher suite negotiation and ensure Let’s Encrypt certificates are valid before public cutover.

Utilizing local hosts file overrides provides an essential quality assurance safety net, preventing customer-facing downtime and ensuring 100% flawless website migrations.

Testing your migrated website using local hosts file overrides ensures that database connections, SSL certificates, payment gateways, and theme assets are 100% functional before updating public DNS records.

About the author

Blog

DevOps architect and Linux sysadmin specializing in server hardening, OpenLiteSpeed performance optimization, and free cloud hosting infrastructure.

Leave a Comment