How-To: Site Migration

It finally happened: You need to migrate to a new host. But you’ve never done it before, and it needs to be done sooner rather than later. What does it take to migrate a site between servers or hosting providers? Let’s demystify the process together.

First, we must define two very important terms:

Source Server: This is the server where your site is currently live. To determine where your site currently resolves, you can use a DNS query tool, such as dig.
Destination Server: This is the server on which your site will arrive at the end of its migration process. The destination server can be another server on the same account, or a server from an entirely different hosting provider.

As a whole, the migration process breaks down into three major phases:

Phase 1: Preparation – In which the required information is gathered from the source server and the destination server is prepared to host the site.
Phase 2: File/Database Migration – In which the files are copied from the source server to the destination server.
Phase 3: Deployment – In which the migrated files are configured and placed in their live position on the destination server. 

Phase 1: Preparation

To start, gather the following information from the source server:

  • FTP or SSH User
    The FTP/SSH user will be used to transfer the files between the servers. SSH is the preferred tool as it tends to simplify certain processes. Fair warning, though: The learning curve for SSH tends to be pretty steep.
  • Database Information
    Most of the database information can be found in the configuration files for the website. For instance, a WordPress installation will have the database information required in the wp-config.php file for the site. You will need this information to create a database export on the source server.
  • Web Directory Information
    This information may be defined in the configuration file for the site, or it may be referenced in the database.

Now, you need to prepare the destination server. On the destination server, go ahead and create the domain entry, create the database/database user, and create an FTP or SSH account you will use to transfer the site files.

The final stage of preparation is lowering the TTL value for the domain to minimize DNS propagation in phase 3 (which can be done wherever the name servers point). Additionally, the site should be placed into maintenance mode while the migration is in progress in order to ensure all data is transferred to the destination server.

Phase 2: File/Database Migration 

This phase tends to take the longest, so roll up your sleeves! The required transfer time is dependent on the size of the site and the number of files. A common (and easier) option is use an FTP client, such as FileZilla, to migrate the files. This will require downloading the files from the source server to a local computer running FileZilla and then uploading the files from the local computer to the destination server. Yet, this sort of transfer leads to a longer total migration time. Ideally, the preferred method is to directly transfer the site from the source server to the destination server via SSH.

But never fear: There’s an easy way to speed up the migration process. First, create a .tar chive of the site and the database on the source server, which will allow you to simply transfer the single tar file between the servers. Then, you will need to expand the archive file on the destination server.

For safety’s sake, back up the database as well: Create a database export on the source server by using either a browser-based tool, such as PhpMyAdmin, or via the mysldump command if you have SSH access. I strongly suggest using the “Add Drop Tables” option when creating a database export, as it will allow you to easily re-import the database to the destination server in case of human error. Finally, transfer the database export file (.sql) to the destination server.

Phase 3: Deployment

This final phase will place the files into their “live” position on the destination server, update any configuration files associated with the website, and import the database to the destination server. If you are using an FTP client for migration, simply upload the files directly in to the web directory for the domain. (For instance “~/public_html on a CPanel server”). If you are using SSH, you can use the “rsync” utility to move files between directories on the server.

Next up: Importing the database files on the destination server. Once again, you can use a browser-based tool, such as PhpMyAdmin, or the “mysql” utility via SSH. Make sure that you are importing the database to the destination server.

After the files are in place and the database has been imported on the destination server, next up is updating the configuration files for the site. Chances are, you will need to update the database connection string in any configuration files for the website (for instance, wp-config.php). Additionally, update any references to the old source server file path with the destination server file path. In some cases, the file path is referenced in the database. You can use a third-party tool, such as InterConnect’s Search-Replace Tool, to find and update references to the old file path.

Once the site files are in place, the database is imported, and the configuration files are updated, there’s just one final step: Testing the site on the destination server. The best way to test (before pointing DNS to the new server) is to edit your local computer’s “hosts” file. Our Community page contains some very helpful documentation to help you update your hosts file.

Checklist
Here’s a quick checklist for your final test:
1: No errors displayed on the page,
2: The destination server environment is compatible with the site, with no major errors, and
3: All site functions work correctly (e.g. contact forms and shopping carts).

Once you have confirmed that the site is operating correctly on the destination server, update the DNS to point the site to the destination server.

Final Thoughts

As a whole, the site migration is a moderately difficult (yet doable) task. There are many potential pitfalls that can complicate the process. If you require professional assistance with a site migration, Media Temple’s team of engineers, CloudTech, can help.

Otherwise, it is quite a rewarding task and great skill to possess. I encourage anybody interested in operating in web development to go ahead and give it a try.

Good luck!

 

 

About the Author CloudTech is Media Temple's award-winning team of engineers that helps clients of all sizes get the most out of their Media Temple services. From on-demand care to 24/7 site protection, CloudTech provides expert-level support around the clock. More by this Author