Move a Website to a New Server - The Seamless Way

Learn how to move a busy website with lots of user-generated content from one server to another. This article guides you through all the steps involved.

View from flying planeIn 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:

  1. 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.
  2. 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.
  3. Configure your email program to check both mail servers. This avoids any email getting lost during the transition.
  4. Put up a holding page. This prevents visitors adding new content to your old site during the changeover period.
  5. 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.
  6. 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.
  7. Test everything works. Now the new site and email are live, check they all work correctly.
  8. Redelegate the domain. You can now safely change the domain's nameservers at your registrar. This change will take 24-48 hours to complete.
  9. 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.

I strongly recommend reading the whole article from start to finish before attempting anything! Also, no two hosting setups are the same, so consider these as general guidelines. If in doubt, ask your hosting companies (old and new) for specific advice!

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.)

A few terms explained:

  • A zone file is a text file that contains all the records (typically between 10 and 20) for your domain.
  • A domain record can do several things, including pointing a hostname (such as www.example.com or mail.example.com) to an IP address; pointing a hostname to another hostname; and indicating which mail server handles email for the domain.
  • The master (sometimes called the primary) nameserver is the nameserver that contains the authoritative records for the domain. Change a record on the master nameserver, and all other nameservers for the domain automatically pick up the change.

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.

You might also see the TTL expressed in seconds. For example, 86400 is 86,400 seconds, or 1 day.

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

If you don't have root access to the nameserver then you'll probably need to ask your hosting company to make these changes for you.

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.

Old nameserver or new?

In this article I'm assuming you'll be changing the TTL and updating the domain records on your old (existing) hosting company's nameserver. Once the records have been updated and everyone is looking at the new server, you'll then redelegate your domain to the new company's nameservers. This is usually the simplest approach, as you only have to change your records — or get someone else to change them — once.

However if your old hosting company won't let you access their nameserver — maybe it's their policy, or maybe they're sulking because you're leaving them! — then you can make the changes on the new company's nameserver instead.

In order to do it this way, you'll need to do the steps in this article in a slightly different order:

  1. First, make sure you point the new nameserver's domain records for web and email to the OLD web/email server. They'll probably default to the new server, which would mean that when you redelegate your domain (see Step 3 below) there will be a couple of days when people are looking at both the old and the new servers — precisely what you want to avoid! Instead, you want both nameservers to serve up the same records during the redelegation period, so that everyone is still looking at the old web/email server.
  2. Set the TTL for the domain on the new nameserver to 5 minutes.
  3. Redelegate your domain to the new nameservers, then wait 24-48 hours so that everyone is using the new nameserver.
  4. Move the site and email, put up a holding page, and so on, as described below.
  5. Change the domain records on the new nameserver to point to the new web/email server.
  6. Change the TTL on the new nameserver back to 1 day, then shut down the old hosting account.

If all this DNS stuff sounds a bit too involved, ask your hosting company for help. DNS can be a tricky topic and it's easy to end up in a situation where your site is inaccessible for a couple of days, so if in doubt get the experts to do it!

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:

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".

If you're using Microsoft IIS instead of Apache then you can also do URL rewriting; however, IIS uses a different format for rewrite rules. Here are some instructions for converting Apache rewrite rules into IIS format.

A good — albeit fiddly — alternative to using a holding page is to get the website on the old server to work with the database on the new server. That way, any new content added on the old site actually gets added to the new server's database. This can be a good approach if you have a very busy site and don't want any downtime. However, unless you're a database guru then it's probably best to ask your hosting company for help with this!

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.

Often the web and email servers are on the same machine, but they might be on different machines. If so then you'll need to update the zone file with 2 different IP addresses — one for web, and one for email.

You may find that there are other entries in your zone file that also point to your old server's IP address. If you're not sure which entries need changing, ask your hosting company for advice.

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! :)

Follow Elated

Related articles

Responses to this article

There are no responses yet.

Post a response

Want to add a comment, or ask a question about this article? Post a response.

To post responses you need to be a member. Not a member yet? Signing up is free, easy and only takes a minute. Sign up now.

Top of Page