WPSandbox Connected Computers

How to Test Your Newly Migrated WordPress Site Before Changing DNS

If you need to test drive WordPress, Try it now!

Sharing is caring!

Migrating a WordPress site to a new host can be a daunting task. Your site has been sitting on the old hosting for quite some time and for this reason is relatively stable but it’s time for a switch. 

Why testing the new WordPress hosting is important before you flip the DNS switch?

One of the most critical steps in the domain migration process is testing the site thoroughly

and also how the WordPress site behaves on the new hosting before you acutally switch the DNS settings.

There could be incompatibility issues or the server is running different versions of the underlying software e.g. Apache, nginx, php, MySQL/Mariadb etc which can lead to various problems such as broken links, missing images, or even a complete site crash. By testing the site beforehand, you can ensure that all elements are functioning correctly and that the migration was successful.

This ensures that everything works correctly on the new host and prevents downtime or other issues for your visitors and customers.

For this reason it’s also a good idea to keep the old hosting active for some time after the migration because sometimes even after a thorough testing a new issue will popup.

In some cases it makes sense to move the site back to the old hosting until a new one and a more compatible one is found.

The Solution

The solution is pretty simple: modify the hosts file and point your domain to the new server.

Normally your computer/browser will check your domain’s registrar for the authorized name servers (NS) and will then ask them what’s the server’s IP address that hosts your WordPress site (A records for @ and www records).

The thing is before the computer even tries to go on the internet and find your domain registrar’s Name Server records it will check the hosts file to see if there’s an entry there.

If there is it will be used. The format is pretty simple. It’s an IP address followed by the one or ore hosts (e.g. example.com) separated by space. One per line. The format is the same for Windows, Mac, and Linux. The hosts file is stored in different locations on each of those platforms. We’ll explore that later in this article.

Important Note: it’s just one or more hosts i.e. there’s no https:// prefix

11.22.33.44 yourdomain.com www.domain.com

Tip: If you want to temporarily deactivate a record you can prefix it by a pound sign # this will be 

interpretd as comment and will not be processed.

Importance of Backing Up the Hosts File

Before making any changes, it’s essential to back up your hosts file. That way you can restore the original settings if something goes wrong or if you need to revert to the previous configuration.

How to find the IP address of the new hosting?

  • ask your hosting provider
  • ask your developer
  • you can log into your control panel and usually on the right hand side there should be an IP address

How to modify the hosts file on Windows

On Windows the file is usually in C:\Windows\System32\drivers\etc\hosts

If you have installed Windows in a different folder then the location will be 

YOUR_WINDOWS_DIR\System32\drivers\etc\hosts

You will need administrator privileges to edit the file.

You may need to right click on the start menu and then run explorer as administrator.

then navigate to the to the folder that has the hosts file.

Backup Create a copy of the file e.g. hosts_DATE

Open Notepad as an administrator.

Navigate to C:\Windows\System32\drivers\etc\hosts.

Add a new line at the end of the file with the new server’s IP address and your domain name (e.g., 11.22.33.44 www.yourdomain.com).

Save the changes and close Notepad. 

when updating the file you may need to put the file name in quotes to ensure that notepad won’t add .txt extension.

this may not be necessary but 

Clear your DNS cache by running 

ipconfig /flushdns in Command Prompt

How to modify the hosts file on Mac

Open the Terminal application.

Backup (Linux & Mac): Use the cp command in Terminal to create a backup 

e.g., sudo cp /etc/hosts /etc/hosts.bak

Use a text editor like Nano to open the hosts file: 

sudo nano /etc/hosts

Enter your Mac password when prompted.

Add the new server’s IP address and your domain name to the end of the file.

Save the file by pressing Control + X, then Y, and hit Enter.

This is optional

Flush the DNS cache by running sudo killall -HUP mDNSResponder.

How to modify the hosts file on Linux:

Open Terminal or if you’re using shortcuts press CTLR+ALT+T)

Backup (Linux & Mac): Use the cp command in Terminal to create a backup 

e.g., sudo cp /etc/hosts /etc/hosts.bak

Edit the hosts file using a text editor such as Nano: sudo nano /etc/hosts

sudo /etc/hosts

Add the new server’s IP address and your domain name to the end of the file. Keep existing contents.

Save and exit by pressing Control + X, then Y, and hit Enter.

Flush the DNS cache with a command appropriate for your distribution (e.g., sudo systemctl restart NetworkManager).

11.22.33.44 site.com www.site.com

Next step: test if you’re connected to the new hosting

Create a temporary text file called 1.txt and place it into site’s root directory e.g. public_html or www or htdocs etc.

You can do this via your control panel. After you login search for file manager.

Create a file named 1.txt and enter some random text. e.g. 111

Close your browser just in case and then reopen it (to ensure the new IP is accessed and navigate to site.com/1.txt or whatever you named the file.

if the change in the hosts was successful you’ll see the contents of the new file.

you can then start heavy testing the site.

Thoroughly check all functionalities, links, and images. If everything looks good, you can proceed to update the DNS settings to point to the new server.

Clean your hosts file. If all is good then you can either remove the line you just added or put a pound # sign to turn it off.

Related

https://www.howtogeek.com/27350/beginner-geek-how-to-edit-your-hosts-file/#editing-the-hosts-file-on-windows-10-or-windows-11

Sharing is caring!

If you need to test drive WordPress, Try it now!

Leave a Comment

Your email address will not be published. Required fields are marked *