Are you looking to migrate a site with zero downtime? Usually, you would have to wait until a domain is set up and the DNS finishes updating in order to install a new website. In this guide, we will show you how to edit the hosts
file so that you can migrate a website with zero downtime while the old site is still live.
Editing the Host File
Having little to no downtime when moving a site is ideal. To install the new site while the Domain is still pointing to the old server, you can force your computer browser into thinking the DNS has already been updated by editing the computer hosts
file. You can then access the new website and install a backup from the original website.
Using Windows
If you are using Windows, the best option is to open Notepad using administrator privileges.
Search for “Notepad” on the Start menu, right-click on the Notepad icon, and then select “Run as administrator.” Click “Yes” on the prompt that appears.
Next, go to File » Open and then navigate to C:\Windows\System32\drivers\etc
folder. Finally, select the hosts
file and open it. You may need to select “All files” for the file type before you can see the file.
Using a Mac
If you are using a Mac, then you need to open the Terminal app and enter this command to edit hosts
file:
sudo nano /private/etc/hosts
You can then edit the host file using the nano program in the Terminal app.
Changing the Domain
For both Windows and Mac users, scroll down past all the lines that begin with #.
Enter the IP address for the server, followed by a space, and then the domain for the website. For example, the following line would make the domain “www.example.com” point to a server with the IP address 192.168.1.22.
192.168.1.22 www.example.com
Be sure to save the file. You can now access your new website on your computer using the domain.
Installing the backup
Now you can install the website and launch it using the following steps.
- Browse to the installer.php and install the site. (See this guide for a full walkthrough.)
- Test to ensure everything is working
- When you are ready to launch the new site, go to your domain registrar and switch the Domain to your new host’s DNS servers
- After you are confident the DNS changes have propagated, remove the entry in your computers
hosts
file
That’s it! We hope this guide helped you learn how to migrate a website with zero downtime.
If WordPress is already installed on a new site, you can import a backup into WordPress. Check out our guide here to learn about “Importing a Backup using Duplicator Pro”.