How to Migrate Your Site to New Server Without Any Downtime

If you own/manage a website, it is inevitable that you will have to change your web host one day. It could be due to the poor services of your current host, or that your site traffic exploded and you need to move on to a bigger host to accommodate the traffic. Whatever the case, most people will agree that it is never a joyous event to switch server. Your site will be down/unstable/inaccessible during the migration period and it could potentially lead to loss of sales. In this article, we are going to show you how you can migrate your site to a new server effortlessly and without any (or minimal) downtime.

There are two main type of web hosting: Shared hosting and VPS/Dedicated hosting. Shared hosting means that the site is hosted in a shared environment and share the same IP address as hundreds (or even thousands) other sites. In shared hosting, the administrative control given to the user is usually very limited, so there is practically no way to manipulate the DNS feature. On the other hand, VPS/dedicated hosting gives the users absolute control over their servers and they can play around with the DNS feature to reduce the downtime. Let’s take a look below at how we can reduce the downtime for these two hosting environments.

Note: This tutorial assumes that you are using cPanel/WHM for your site hosting.

Migrating site in a shared hosting environment

1. Back up all the files in the old server. You can easily do this with any FTP programs. If you are running a dynamic site (like WordPress), remember to backup your database as well (via the PhpMyAdmin->Export)

2. Set up the new server. Copy all the files from the old server to the new server. Pay extra attention to keep the file structure intact. For dynamic website, set up a new database (with the exact same name and password) and import the whole database in. Again, make sure that the database structure is intact.

For static website

3. Go to your domain registrar and change the nameserver to the new server. That’s it. The DNS will take 24-48 hours to propagate. During this period of time, your site will be unstable, oscillating between the new and old server, but since it is a static website, so your visitors won’t see any differences. Avoid making any changes during this period of time.

For dynamic website

4. You will need to configure your site to point to the database at the new server (some web hosts don’t allow remote access to their database, so check with your web host before you begin). Open your cPanel in the new server. Scroll down until you see the icon Remote MySQL. Click on it.

migrate-site-remote-sql

Enter your domain name in the field and click “Add Host“.

migrate-site-add-host

Log out of cPanel. In your old server, open your database configuration file (for WordPress, it is the wp-config.php file). At the field where it asks you for database hostname detail, change it to the IP address of the new server. In WordPress:

Save and upload to the old server.

5. Go to your domain registrar and change the nameserver to the new server. That’s it. While the DNS is propagating, your visitors will see content from the old server. However, as the database is pointed to the new server, all changes make on the site will be updated in the new server. Once the migration is done (24-48 hours time), your new server will be up and running with all the changes make during the migration.

Migrating site in a VPS/Dedicated hosting environment

Before we start, it is assumed that all users have root access to their servers and both the old and new servers are running cPanel/WHM.

1. Log in to the WHM in the old server. On the left panel, scroll down till you see the “Edit DNS Zone” link. Click on it.

migrate-site-edit-dns-zone

2. Select the domain that you are migrating.

3. Look out for this field where it shows the domain name and the IP address.

migrate-site-dns1

Change the 86400 (or 14400) to 300. Save the changes.

migrate-site-dns2

What you have just done is set the TTL (Time To Live) value to 5 minutes so the DNS client will only cache the information in that record for 5 minutes (the common setting are 24 hours and 4 hours). Now you have to wait for 4-24 hours for this TTL value to propagate, depending on the original value.

4. Meanwhile, you can backup your old server and migrate all your files and databases to the new server. Test the new server to make sure that everything is working fine.

5. When you are ready to migrate the site, log into your old server WHM again. Go to the DNS zone page. This time, change the IP address to the new server’s IP. Save the changes.

migrate-site-dns3

What you have just done is to set this as a relay and point it to the new server.

6. Go to your domain registrar and change the nameserver to the new server. That’s it. In as little as 5 minutes, your new server will be up and running. As in all cases, the DNS will take 24-48 hours to propagate, so meanwhile, keep your old server intact (do not delete any files or terminate the service) until the DNS propagation has finished.

Let us know in the comments if this is useful to you.

Image credit: EJP Photo

14 comments

  1. Nice article, I wasn’t aware of the flexibility when performing DNS changes.
    I’ve personally found my DNS to be quite fast, but this is rather helpful when time is of utmost importance!

    • @Shawn: Some ISPs cache the DNS setting so they can avoid returning to get the setting regularly. It is still best to change the DNS timing to 5mins and force the ISPs to return at a shorter interval to grab the new setting.

  2. Nice post. I came across this after just having trouble with my server switch over. My provider said it would be seemless however they now tell me I have to wait for 24-48 hours for propagation.

    Is this something a provider should know? Before starting the migration I asked all the necessary question to ensure no/limited down time. And if there is to be down time then getting a temporary holding page to tell people it is maintenance.

    Then when I show them your method they tell me “oh… yes we can do it this way”… so why didn’t they just do it in the first place?

    Anyway… thanks for clarifying it can be done with minimal downtime.

    • I think every system administrator will know this trick. It is just that the process is too troublesome and most of them wanted the easy way out (for them). I have switched web hosts several times, so I know how you feel to see downtime for your site.

  3. Most hosts do not set the time to live due to all the extra steps. For one, it’s very seldom that client’s have any clue what DNS is, so even presenting the the concept of A record IP change might result in a stalled or lost sale.

    When we move an account in from another host I often present this to client’s as an option, since we do free website migration (sometimes several a day).

    Though occasionally I run into clients who are easily confused. I know I’ve lost a few sales in the past 10 years after discussing the concept of propagation and how to reduce it’s effects.

    • It is a very good thing that you even bother to explain to your client and provide them with this alternative. Some (or most) web host don’t even do it at all, even though they promised zero downtime migration.

      • Truthfully, for those hosts who don’t present this methodology, it’s often not possible to change the time to live settings, as client’s do not have advanced DNS accessibility. So I wouldn’t’ say a host is bad for not promoting the concept. This setup can be tedious…

        Likewise, you can’t just change the time to live setting in DNS down to five minutes and instantly start the migration process. You still have to wait, till next day is what I tell our clients, to truly make it seamless (which is discussed a bit loosely in the article above as well).

  4. I have a MASTER RESELLER account with in shared servers with a hosting company. Now, I want to MIGRATE ALL of our clients webstes from current shared server to VPS/Dedicated hosting environment
    – both the old and new servers are running cPanel/WHM. I’ve login and checked WHM and saw DNS Zone but could not find “Edit DNS Zone” there. How do I do the MIGRATION?

    – Soji F.

    • Since it is a shared server, even though you are a master reseller, you still won’t have permission to edit DNS setting. I might be wrong, but the best thing you could do is to email your web host and ask them about it.

  5. Hello,
    I wanted to ask this..
    For a wordpress blog, is it not possible to change the name servers with the domain registrar and set up the same blog with the new host using a blog back-up?
    Why are all the steps for remote access and changing the config.php required on the old server..

    • You can, but that is provided your site is static during the name server transition period. If you have make amendment to your blog, or someone adds a comment during this period of time, it won’t be captured in your new server.

  6. Thanks for the post Damien, I already bookmark it because I’ll use it in few days time. I want to move VPS to other host and just looking for the best way. I don’t have any client on the hosting but I want to keep all my websites online and don’t let my readers down. Just hope this will still work :)

Comments are closed.

Sponsored Stories