In Move a Website to a New Server – The Easy Way, I looked at a simple way to move your website and email from one hosting company to another. This approach is fine for sites that don’t have too much user-generated content. However, if you run a busy site with lots of blog comments, forum posts, or customer orders then things can start to get messy with this approach.
Why? Well, when you move your domain to the new hosting company’s nameservers — a process known as redelegation — it usually takes a couple of days for the change to propagate around the internet. During this time, some visitors will be seeing your site on your old server, while others will be looking at your new server. This means that you’ll end up with new content being added to both the old site and the new site at the same time, which can be a major headache!
Fortunately, there’s a way round this problem. It’s a bit more fiddly than the “easy” approach, but it does result in a seamless transition. The great thing about this approach is that there will only be a few minutes where both the old and new servers are being accessed at the same time, as opposed to several days.
So, here are the steps for a smooth server move:
- Reduce the TTL for your domain records to 5 minutes. This means that when you change your records later on, everyone will pick up the change within 5 minutes. You need to do this step at least 24-48 hours beforehand, depending on the old TTL setting.
- Move your site and test it. This involves backing up the site, setting up your web space on the new server, uploading your site, and checking it all works.
- Configure your email program to check both mail servers. This avoids any email getting lost during the transition.
- Put up a holding page. This prevents visitors adding new content to your old site during the changeover period.
- Transfer site data again. To make sure your new site is an exact copy of the old, you’ll need to re-transfer any last-minute changes that occurred on the old site.
- Change your domain records. This is the step that gets everyone looking at the new server. Since your TTL is 5 minutes, the changeover happens almost instantly.
- Test everything works. Now the new site and email are live, check they all work correctly.
- Redelegate the domain. You can now safely change the domain’s nameservers at your registrar. This change will take 24-48 hours to complete.
- Shut down the old account. Once you’re happy that the domain is moved across you can close down your old hosting account.
Ready? Let’s get going.
1. Set your domain’s TTL
The key to a smooth transition between servers is to reduce the TTL (time to live) for your domain. The TTL tells other computers on the internet how long they can cache (store) your domain records before requesting them again from your nameserver.
By default, the TTL for a domain is usually set to a fairly long period such as 24 or 48 hours, to prevent the nameserver being hit with too many requests. This means that, even if you change your domain records to point to your new web server and mail server today, there will be a period of 1-2 days when some computers still have your old domain records while other computers are picking up the new records. This means that you can’t be sure that everyone is viewing your new site until at least 2 days after you make the change.
The solution, therefore, is to reduce your domain’s TTL temporarily down to 5 minutes, ideally at least 48 hours before you plan to change servers (this allows enough time for everyone to start using the new 5-minute TTL). That way, when you change your domain records to point to your new server — which you’ll do later on — you can be sure that everyone will be looking at the new server within 5 minutes of making the change. After the change, you can redelegate your domain to the new nameservers at your leisure.
To change your TTL, you’ll need access to your domain’s zone file on the master nameserver that handles your domain, which will probably be a server at your old hosting company. (Failing that, you’ll need to be able to speak to someone at your hosting company that can make these changes for you.)
Open your zone file now. If you have root (admin) access to your nameserver then you might do this by logging into your server via SSH and editing the file — for example:
sudo pico /etc/bind/example.com.hosts
Or you might be able to use a Web-based control panel such as cPanel’s WHM or Plesk to edit the zone file.
The first line of the zone file will probably look something like this:
$TTL 1d ; default TTL for zone
This setting controls the TTLs for all the records within the zone. In the above example it’s set to 1d (1 day). Reduce it down to 5 minutes as follows:
$TTL 5m ; default TTL for zone
Often, changing this default TTL changes the TTLs for all the records in the domain. However, sometimes individual records have their own TTL values that override the default. For example:
www.example.com. 2d IN A 1.2.3.4
In the above example, the www.example.com
record has its own TTL of 2d. You want to change this to 5 minutes also:
www.example.com. 5m IN A 1.2.3.4
Alternatively, remove the "2d"
after the domain name to make the record use the default TTL for the zone.
Once you’ve changed the TTL value(s) in the zone file, you need to increase the serial number in the zone file by 1 so that other nameservers pick up the changes. The serial number looks something like this:
970763466 ; serial
In the above example, you’d change the serial number to 970763467, then save the zone file. (If you’re editing your zone via a web-based control panel then it will probably update the serial number for you.)
Once you’ve made the changes, restart your nameserver so that it picks up the changed zone file. For example, if you’re running the BIND nameserver you might type the following on your server:
/etc/init.d/bind9 reload
To check that the TTLs have been properly set, you can use a lookup tool such as dig
(available out of the box on Linux and Mac OS X; here’s a Windows version). For example, if your nameserver has an IP address of 4.3.2.1 and your domain name is www.example.com
, open a terminal window or command prompt on your computer and type:
dig @4.3.2.1 www.example.com
You should see something like this in the output:
;; ANSWER SECTION: www.example.com. 300 IN CNAME example.com. example.com. 300 IN A 1.2.3.4
where “1.2.3.4” is the IP address of your old web server. Notice the all-important “300” in the output — this means that your TTLs have been reduced to 300 seconds, or 5 minutes.
2. Move your site and test it
Now that you’ve dealt with the nameservers, it’s time to move your site files and data across to the new web server, and test it all works. I’ve already covered these steps in my previous article, so just follow them through:
- Back up your site
- Set up your web space and mailboxes
- Upload your site to the new server
- Check the site works
3. Set your email software to check mail on both servers
Although the transition period will be short — around 5 minutes or so — there’s still a chance that some email might be sent to your old server during the changeover. Therefore it’s a good idea to get your email program to check both mail servers before the move, and for a few hours afterwards.
4. Put up a holding page
In order to prevent visitors from registering or posting content on the old server while you transfer the DNS, you can redirect them to a temporary holding page on your old site. You can do this very easily with Apache by adding the following .htaccess
file to your website’s document root:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !.*.gif$
RewriteCond %{REQUEST_FILENAME} !.*.jpg$
RewriteCond %{REQUEST_FILENAME} !.*.css$
RewriteCond %{REQUEST_FILENAME} !.*.js$
RewriteCond %{REQUEST_FILENAME} !.*down.html$
RewriteRule ^(.*)?$ /down.html
This redirects all page requests to a page called down.html
in your document root folder. This can be a simple page along the lines of “we’re currently moving our site — please check back in 5 minutes”.
5. Re-transfer data from the old server to the new
If your site is busy then it’s likely that visitors have added some new content to your old server in the period between transferring over your database (Step 2) and putting up your holding page (Step 4). So, before you start moving visitors over to the new server, you’ll want to copy these latest changes over to the new database.
To do this, just repeat the process of exporting and importing your data. (If your user-generated content includes uploaded images or other files then don’t forget to copy over your uploads folder too.)
6. Change your domain records to point to the new server
Now that your site and email accounts are working on your new server, it’s time to tell everyone to use the new server instead of the old one.
To do this, you need to change your domain records in your old nameserver so that they point to your new web and email server. Once you make this change, everyone will quickly start using your new server — usually within 5 minutes.
So, edit your zone file again (as described in Step 1) and change the records so that they point to the new server’s IP address.
For example, your current zone file might have the following records:
example.com. IN A 1.2.3.4
www.example.com. IN CNAME example.com.
ftp.example.com. IN CNAME example.com.
mail.example.com. IN A 1.2.3.4
example.com. IN MX 1 mail.example.com.
If your new web/email server had an IP address of 5.6.7.8 then you’d change these records to:
example.com. IN A 5.6.7.8
www.example.com. IN CNAME example.com.
ftp.example.com. IN CNAME example.com.
mail.example.com. IN A 5.6.7.8
example.com. IN MX 1 mail.example.com.
As explained in Step 1, don’t forget to increase the serial number in the zone file by 1 so that other nameservers pick up the changes. Then restart your nameserver.
If you don’t have the ability to edit your own zone file, ask your old hosting company to make the change for you.
To confirm that the nameserver is returning the new server IP address, you can use dig
again. For example, if your nameserver has an IP address of 4.3.2.1 and your domain name is www.example.com
, open a terminal window or command prompt on your computer and type:
dig @4.3.2.1 www.example.com
You should see a result along the lines of:
;; ANSWER SECTION: www.example.com. 300 IN CNAME example.com. example.com. 300 IN A 5.6.7.8
where “5.6.7.8” is the IP address of your new web server. You might also want to run the same test on your domain’s other nameserver (most domains have at least 2 nameservers) to make sure it’s picked up the change too.
Now all you have to do is wait 5 minutes while all nameservers and other computers on the internet pick up your DNS changes. After 5 minutes, pretty much all computers will now be using your new server rather than your old. Your new server is officially live!
7. Test everything works
Once the switch has been made, it’s wise to check that your site and email work properly on the new server, and fix any problems that you find.
8. Redelegate the domain
Now that everything has been safely moved over to the new server, you can redelegate your domain to the new hosting company’s nameservers. This effectively switches control of your domain records to the new hosting company, allowing you to close down your old hosting account and nameserver.
Remember that the redelegation process can take 24-48 hours to complete. However, since both the old and the new nameservers point to the new web and email servers, the redelegation process won’t affect your site or email.
To redelegate your domain, follow these steps.
9. After a few days, shut down the old hosting account
Once a few days have passed, everyone should be accessing your new web server, email server, and nameserver instead of the old servers. You can now close your old hosting account.
You’ve now successfully moved your site and email from your old hosting company to your new one, and you’ve retained all your user-generated content and minimized downtime to boot. Give yourself a pat on the back, and book that vacation. You’ve earned it! 🙂
Leave a Reply