Testing Website Transfer on New Host Before Updating DNS

, ,

When migrating a website from one hosting provider to another we can initiate the migration all the way up to the final steps of updating the DNS and installing the SSL certificate.

This would allow us an opportunity to ensure that the migrated site, waiting on the new server, is fully operational (minus the SSL) prior to going live. For example, imagine not setting the database credentials correctly and when the DNS change takes effect you and any visitors are welcomed with a “Database Connection Error“. I call that a “nobueno” situation and now you must hurry to correct the blunder.

 

Updating your Hosts File to check Migrated Site on New Server

The hosts file on your local PC may be used to map domain names to IP addresses. Using the hosts file, you can manually change the IP address that you resolve a given domain name to. This change only affects your own local PC without affecting how the domain is resolved worldwide.

You will need to obtain the IP address of your website from your new server. With that information, you can now edit the hosts file on your local PC. The location of the hosts file, depending on the operating system that you are using, is:

  • Windows
    • C:\Windows\System32\drivers\etc\hosts
  • Linux
    • /etc/hosts
  • Mac OS X
    • /private/etc/hosts

 

Manually Pointing a Domain to an IP Address

For example, if you wish to point yourwebsite.com to the new server IP address 1.2.3.4 open your hosts file (with administrator rights) and add the following line to the bottom of the hosts file:

  • 1.2.3.4 yourwebsite.com www.yourwebsite.com

Save the hosts file and clear your web browser’s cache. Now when you try visiting the domain http://yourwebsite.com in your browser it should take you to the site hosted on the new server with IP 1.2.3.4.

  • If you are unable to save the hosts file, make sure you opened your editor with administrator rights.
  • Make sure you don’t have a ” # “ sign in front of the IP address line we entered above as this will comment out / deactivate the line.
  • When you visit yourwebsite.com you may get an SSL error stating that “Your connection is not private
    • Click the “Advanced” button then click “Proceed to 1.2.3.4 (unsafe)

 

 

This will now make your PC resolve yourwebsite.com to 1.2.3.4. Note, you may need to clear your web browser’s cache. More detailed instructions on how to locate and edit the hosts file on different operating systems are available below:

 

Windows 10 & 11

  • Press the Windows key.
  • Use Search to find Notepad.
  • Right-click Notepad and select Run as administrator.
  • From Notepad, open the hosts file located at: C:\Windows\System32\drivers\etc\hosts
    • In case Notepad does not show any files in the etc folder, switch the type of file from “Text Documents” to “All Files”.
  • Add the line above (with your new server’s IP address and desired domain name) and save your changes.

 

Linux

  • Open up the Terminal;
  • Use the nano command line text editor or a different one you have available to open up the hosts file. The command with nano is as follows (the command will require your Linux user’s password):
  • sudo nano /etc/hosts
  • Add the appropriate changes in the hosts file;
  • Use the Control and X key combination to save the changes.

 

Mac OS X 10.6 through 10.12

You should be logged in with a user with administrator privileges on your MAC.

  • Open Applications > Utilities > Terminal.
  • Edit the hosts file with a command line text editor such as nano by typing the following line in the terminal (the command will require your Mac user’s password):
  • sudo nano /private/etc/hosts
  • Add your changes at the bottom of the file;
  • Save  the changes with the Control & X key combination, followed up by Y and then Enter

 

Conclusion

I welcome your thoughts, questions or suggestions on my article on how to testing your website transfer on the new web host prior to going live.

You may support my work by sending me a tip using your Brave browser or by sending me a one time donation using your credit card.

Let me know if you found any errors within my article or if I may further assist you by answering any additional questions you may have.