I can't give you a sure-fire formula for success, but I can give you a formula for failure: try to please everybody all the time.
Herbert Bayard Swope

Sometimes you just have to accept that your web-site deserves better than your current host provides. Perhaps there’s too much downtime, your site’s pages load too slowly or their support doesn’t. I’m not suggesting you should drop a supplier because of one or two incidents – bad things happen to everyone from time to time – but if there’s a continuing problem and the host isn’t willing and able to solve it then take your business elsewhere!

But changing hosts can be daunting. You read about DNS taking 48 hours to propagate… Will the web site be offline for all this time? What about your e-mail – will you lose important messages?

Well, the good news is, if you do everything right you can transfer a site from one host to another without any significant downtime. Even a dynamic site (where all content is generated on-the-fly from a database) can be transferred with just a minute or two of showing a maintenance page. But all too often web site transfers don’t go well – sometimes there’s a lot of downtime and other disruption, even more than 48 hours in bad cases. When this happens it’s usually because the site owners don’t know what they should be doing or how to get it right first time.

So here’s a step-by-step guide. If anything’s not clear or if you find other problems feel free to add a question / comment using the form at the foot of the page. And if you’d like me to do all this for you, please see the services page.

How to migrate your web-site from one host to another with zero down-time

Open your new hosting account

Sign up for your new hosting account leaving plenty of time before the old one expires – a month is good, two weeks is ok, one week should be an absolute minimum. Preferably, use the same domain name for the new account as you used for the old one.

Transfer the domain name away from old host (if necessary)

If your domain name is registered through the old host, unless you trust them 100% you should transfer the domain to another registrar. I do trust my hosts but still prefer to keep all domain registrations completely separate from their hosting. When you transfer a domain name between registrars the nameservers it points to should not change, ie. after the transfer you should still be pointing to the old host’s nameservers. Check that this is the case when you request the transfer and confirm it as soon as the transfer is complete.

If your domain name registration is already handled by an independent registrar then you can ignore this step.

Advanced users only – change nameservers early

Do you have control over DNS records at both hosts? If so you can change nameservers early to speed up the move. Propagation of new nameserver information around the internet can take up to 48 hours or even longer – by starting the process early you get a head-start on this, the longest part of the process, and by setting up your new nameservers to provide the same information as the old ones you ensure that nothing changes during the transfer.

So, edit your zone on the new host and change the A records to point to the old IPs, and at the same time reduce the TTL values to between 300 and 600 (5 to 10 minutes). Check you’ve done it right by using “dig @ns.newhost.example.com yourdomain.example.com” on a linux computer, or if you’re running Windows you can find a dig windows binary on Google.

Now you can go to your domain registration control panel and point your domain to the new nameservers. Since both new and old are giving the same information this change will not affect your visitors, and after 48 hours or so almost everyone will be using the new nameservers.

If that’s all a bit daunting or you don’t have access to change the zone records yourself don’t worry – you can skip this step and still make the transfer later (but it won’t happen quite as fast).

Transfer content

If both your old host and the new one are using the same control panel you have an easy way to transfer the content of your web site – take a full backup of the account on the old host, transfer the backup file and restore it on the new hosting account. If you need more specific details on how to do this ask your new host.

In the more general case you may need to set up the new account (domains, databases, mailboxes etc) and then copy files and databases between hosts. Exactly how you transfer files depends on what access you have to both hosting accounts – ideally you’ll have secure shell (ssh) access to both and you can make good use of the excellent linux command line tools: Transferring content using SSH. However some hosts don’t offer SSH access – to me this is good reason to choose a different host but if you need to work within this limitation please see Transferring content using FTP.

Modify configuration filesMost web applications keep important settings in a configuration file where they can be easily edited to suit the hosting account. Examine these files carefully and change any settings necessary – commonly these will be file paths and database connection information. Take note of any files you change.

Test the web site

Up to now your visitors are still seeing your web-site on the old host, and until you’re absolutely sure the site has been transferred correctly you should keep it that way. It’s possible that something went wrong during transfer, or that changes are required to make your site run on the new account (PHP running as Apache module or cgi is a common cause of this). To view the site on the new server while all your visitors are still seeing the old server, please see Testing before dns propagation.

If anything’s not right, now’s the time to fix it – while you’re the only one seeing the new server and your visitors are still seeing your site on the old host. If you do need to make changes take note of each file you change – most likely the configuration files (as mentioned above) and .htaccess files will need changing to suit the new hosting server.

Important: If you’ve edited your hosts file for testing purposes, remember to reverse those changes now!

Schedule the change-over

With everything working on the new server, now you can set a time for the public change-over. If you already changed nameservers you should wait at least 48 hours after making that change to get the benefit of it. In any case, choose a time that will cause least inconvenience to you and your visitors and advise everyone who needs to know. I would allow a 1-hour maintenance window for this, although in practice it should be done within a few minutes.

When the time comes, put your web-site into maintenance mode so no-one can make changes that could get lost during change-over. Many applications have an option in the admin system to do this, but if not you can simply add a small page called maintenance.html containing your message, something like this:

This site is temporarily down for essential maintenance. We apologise for the inconvenience. Please try again in a few minutes.

Then in your .htaccess file add these lines:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/maintenance.html
RewriteRule .* maintenance.html [L,R]

This redirects all requests to the new maintenance page.

Now repeat the procedure for synchronising files and databases. Using SSH the same rsync command can be used (it will only transfer files changed since the last time you ran it) but you must exclude those files that you needed to change on the new server – see the “exclude” option.

Using FTP you can probably just scan the directories for changed files and download / upload these.

Note, if you’re sure that no files have changed on the old server since your earlier transfer then you can skip this step completely.

The procedure for transferring the database is identical to the earlier transfer. Again, if you’re sure that nothing has changed on the old server then you can skip this.

Depending on your method of setting maintenance mode, this setting may have been transferred to the new server (eg. in the database). You don’t want this – the site should be live on the new server, in maintenance on the old. If you think this may be a possibility then connect to the new server (use the hosts file trick again if necessary) and turn it off.

After completing the final synchronisation your web site should be working on the new server and completely up-to-date. Now you can change over the DNS. If you already changed nameservers then just edit the A records to point to the IP address of the new server and propagation should complete within 5 to 10 minutes (the TTL you set on the A records). If you’re only now pointing your domain to the new nameservers then propagation for this will take longer – commonly only an hour or two but in some cases up to 48 hours.

During this period your visitors will be coming to the new server in increasing numbers but some will still be seeing your web-site on the old server (the maintenance page). If your site is database driven you can allow these visitors full access again after changing the configuration of your application to connect remotely to the database on the new server. To do this you’ll need to edit the configuration file on the old server and also allow remote connections to your database in the new hosting account. After this you can turn off maintenance mode and your site will be back online for all visitors, even though they’re not all using the same server.