When migrating a website to a new server, testing the site on the new server before pointing your domain to the new server is essential to ensure everything works correctly.
One simple and effective way to do this is by modifying your computer’s hosts file. This guide will explain what the hosts file is, why you might need to modify it, and how to make these changes on Windows and macOS.
What is the Hosts File?
The hosts file is a simple text file your computer uses to link domain names to specific IP addresses. It overrides the usual DNS process, so if there’s an entry for a domain in the hosts file, your computer will use that IP address instead of looking it up online. This is helpful for testing because you can make your computer load a website from a specific server without updating the DNS records and affecting the live site.
Why Modify the Hosts File?
Modifying your hosts file allows you to:
- Test your website on a new server before updating DNS records.
- Verify that all features, plugins, and content are functioning correctly after migration.
- Avoid affecting the live site while troubleshooting or performing updates.
- Resolve potential issues without exposing users to downtime or errors.
By doing this, you “trick” your computer into thinking the domain is already pointing to the new server, even though the live DNS settings remain unchanged.
How to Modify Your Hosts File
Before proceeding, ensure you know the IP address of the new server. You can usually find this in your hosting control panel:
- Log in to your hosting control panel.
- Navigate to the server details section.
- Copy the server’s IP address.
Below are instructions for modifying the hosts file on Windows and macOS.
Steps for Windows
Open Notepad as Administrator:
Click the Start menu, type “Notepad,” right-click on the app, and select Run as administrator.
Open the Hosts File:
In Notepad, go to File → Open.
Enter the file path: C:\Windows\System32\drivers\etc\hosts
and click Open.
Add Your Entry:
At the bottom of the file, add a new line in the following format:
[IP Address] [domain] www.[domain]
Example:123.123.123.123 example.com www.example.com
Save the File:
Go to File → Save and close Notepad.
Test the Website:
Open your browser and enter the domain name to load the site from the new server.
Steps for macOS
Open the Terminal:
- Use Spotlight Search (Command + Space) to search for “Terminal,” then open it.
Edit the Hosts File:
Type the following command and press Enter:
sudo nano /etc/hosts
Enter your password when prompted.
Add Your Entry:
Use the arrow keys to navigate to the bottom of the file.
Add a new line in the format:
[IP Address] [domain] www.[domain]
Example:123.123.123.123 example.com www.example.com
Save and Close:
Press CTRL + O (letter O), then press Enter to save.
Press CTRL + X to exit the editor.
Tips for Testing
Once you have completed modifying your host file it is a good idea to ping the domain to confirm your computer is pointed to the new servers IP address.
On the new web-server it is common to receive a SSL certificate warning, this is expected and will resolve once the DNS records have been pointed at the new server.
Key steps and things to check
- Clear your browser’s cache before testing to ensure you’re loading the correct version of the site or browse the site in an incognito mode
- Ensure you can sign into the admin dashboard and perform basic tasks like creating a new post or editing a page. Investigate any warnings.
- Clear the websites caching plugin to force all pages to be regenerated
- Ensure all aspects of your site load correctly (images, scripts, page elements).
- Test plugins: Appointment bookings, contact forms
- Test the performance of the website on the new website.
Once finished testing, ensure you remove this line!
Alternative Method: Hosts.click
If you do not wish to modify you computers host file or do not have administrator access, one alternative is Host.click
Hosts.click works by providing you a temporary URL and acting as a proxy between your browser and the server. Performance will not be as good as modifying your hostfile, but it will give you an indication that the website is working.
Final Words
Testing your website using hostfile after a migration onto a new server before updating your DNS records is an important step to confirm the migration was successful.
Do you have any questions about testing your website or migrations? Let Us know in the comments below