Whether we are transferring a client's website from another host onto one of Dedicated Manager's hosting servers or moving websites between our own servers, we always want, from the public's perspective, to keep the client's website up and running with zero downtime. The following is a basic framework on how Dedicated Managers implements the transition of a client's website between (Linux) hosting servers safely and securely with zero downtime.
The following is a basic framework of the steps required to transfer a website from its current host to a new host:
Note that transferring email is not included in the framework above. As email has its own DNS records, it can be transferred separately as another (somewhat similar) process.
Among first things to be verified is to make sure the new server to which we are transferring the website has all the major software required to run the website. Along with major software, we should also check the software is running compatible versions. And finally, we need to check for any necessary modules or compilation configurations within the required software.
In reality, if you have full (root) control of the new host, on a simple site, you can be somewhat lazy with this step as you can install and configure any needed requirements on the new hosting server during the testing phase based on errors that arise. Mostly we make sure to verify the current transfer isn't the rare case where proprietary software is running as a system service. Most websites, even if they have proprietary software, will have the software as part of the website and not as a service installed on the server, so it will get copied over as part of the file system transfer.
Most websites need three major services:
Specifically, the set up is most often a LAMP (Linux, Apache, MySql, PHP) configuration:
Within each of those services, specific versions may be required. For example PHP has depreciated a lot of functions over the years. If you the site you are transferring was originally programmed on a version of PHP lower than PHP 5.X, you are probably going to have a lot of code break if the new server is running PHP 7.X. Again, you'll find this out in the testing phase before you move the public traffic to the new server, but it's good to get an idea of what type of struggles you are going to have to complete the transfer.
Rather than installing old software versions on the new server, we always look to upgrade the code to be compatible with the latest software versions. Most of the time this is not a big issue, it usually arises when a client contracts proprietary software to be coded (i.e. via Upwork.com) that can't be updated with a few clicks like a commercial or open source CMS (Content Management System) could. NOTE: If you are running a CMS, it may be easier to simply install the CMS on the new server and use a tool to export the website content and its configurations from the old server and import it to the new server. For instance, if you are using WordPress, simply search for "WordPress Migration Plugin" to move the website to a fresh installation of WordPress on the new server. You can still us the testing techniques described below to verify functionality before switching the public traffic.
The next step to complete in a website host transfer is to export any databases to files. For simplicity, we export the databases to files within the file system to be copied over to the new server. Typically the client has a MySQL database and the command to export the database is fairly simple:
mysqldump --opt -uUSER_NAME -p DATABASE_NAME | gzip > /PATH/TO/FILESYSTEM/DATABASE_NAME.gz
Obviously, you'll need to replace the red all-capitals with the website's information. And don't save this file to the public html directory where it could be exposed to the public.
Though it's rare, some websites will have their own cron jobs which need to be found and transferred to the new server.
The first place to look is in the users 'crontab'. Run the following command (as the user) to view if the user for the website has any cron jobs in its cron table:
#Show the user's cron table:
If there are cron jobs, take a look at the commands to see what's needed. You may need to update any file links if the new server has a different file system structure.
To dump the crontab to a file that can be transferred during the secure copy to the new server:
#Save the users cron table to a file:
crontab -l > /PATH/TO/FILESYSTEM/crontab.data
Again, don't save this file to the public html directory.
Next, you'll need to make sure any links weren't put in the system cron folders. Cron folders tend to differ based on the Linux flavor (Ubuntu, Fedora, Red Hat, CentOS, Debian, etc).
For CentOS a quick way to check for files is to run a command like the following:
#Search for links in the cron directories:
ls -la /etc/cron* | grep USERNAME
This will show any files or links owned by your user in the cron directories. You may just want to pipe this information into a file within the file system to manually recover on the new server.
#Search for links in the cron directories:
ls -la /etc/cron* | grep USERNAME > /PATH/TO/FILESYSTEM/cron.links.data
#scp - logged into the new server
#Note the dot "." at the end of the remote file system as it is needed to copy hidden files starting with a .
scp -rp USER_NAME@DOMAIN.COM:/PATH/TO/FILESYSTEM/. /PATH/TO/NEW/FILESYSTEM/
#rsync - logged into the new server
#Note the trailing slash on the remote filesystem and the lack of it on the local system
rsync -avz --delete USER_NAME@DOMAIN.COM:/PATH/TO/FILESYSTEM/ /PATH/TO/NEW/FILESYSTEM
On the new server you'll need to set up your databases. Typically you'll want to set them up with the same database name and credentials as the previous server, as these credentials will likely be hard coded in the website's application (usually in a "config" file).
Setting up the database can typically be done with phpMyAdmin or with a couple simple mysql commands:
#Logged in as a MySQL user on the new server with permissions to create users & databases
CREATE DATABASE DATABASE_NAME;
GRANT ALL PRIVILEGES ON DATABASE_NAME.* TO 'DATABASE_USERNAME'@'localhost' IDENTIFIED BY 'DATABASE_PASSWORD' WITH GRANT OPTION;
Now you'll want to get the database you previously exported (and compressed) and transferred over to the new server as part of the file system into the database. You can use phpMyAdmin or commands similar to the following:
gzip -dc /PATH/TO/FILESYSTEM/DATABASE_NAME.gz | mysql -u DATABASE_USERNAME -p DATABASE_NAME
Now you'll need to restore any cron jobs.
#Restore the users cron table to the new server's cron table:
#NOTE: If the file system paths have changed from the old server to the new server, you'll need to first edit this file
If the file system path has changed from the old server to the new server, you'll likely need to make changes to the crontab file before importing or the any paths will be corrupt. For instance, if the user's directory used to be located at "/users/home/USERNAME" and its now at "/home/USERNAME", you'll probably have updates to make.
This is where the fun really begins, because this is where you'll find the differences between the old and the new servers. You'll spend most of your time in this step figuring out how to get the website running smoothly. You'll have to fix configuration issues with different software versions, update code, install needed modules and much, much more.
There are too many issues that will typically arise to fully discuss here. The good news is that you can fix all the issues on the new server while the public traffic is still going to the old server.
One caveat to watch out for is that if the old server is still collecting data (ie memberships, newsletter emails, etc), you may need to re-import that data into the new server. If the data is located in a database, before you switch public traffic via DNS to the new server, have to go back to the old server, export the database again, copy it to the new server and re-import the database. This should not be a big issue if you don't have to make changes to the database for it to run on the new server. If you do have to alter the database for some reason during testing, then be sure to track your changes so you can re-implement them when you re-import the database before switching public traffic over to the new server.
Some articles will tell you to test using a special url on the new server or by using the IP address of the new server.
#Some articles will tell you to test the new website in a browser with a url like:
If configured by the web server, that may work, but often times you'll struggle with the website itself redirecting you back to your domain (on the old server - because you haven't changed DNS yet). Some websites do this because they have multiple domains pointing to them (SEO reasons). Most often it more specifically happens because whoever set up the server was trying to remove having duplicate websites at http://www.domain.com and http://domain.com, which search engines don't like. So when the code sees the URL is not for the specific domain, it may redirect (WordPress does this).
The trick I like to use is to fool your local computer into thinking the domain's DNS has been transferred even though you haven't yet done so. On a windows machine you do this in the hosts file by hard-coding the new server's IP address onto the domain name. Windows checks this hosts file for domains before reaching out to authoritative DNS servers to get an IP address for a given domain. If a domain match is found in the hosts file, Windows does not check any further. Also, updates are immediate, meaning you can change the IP address as much as you want in the hosts file and there's no waiting for the changes to propagate.
# On Windows, edit your hosts file to point the domain to the new server
# The file is located at: C:\Windows\System32\drivers\etc\hosts
# You'll need to open the editor with administrator privileges (right click the icon and choose "run as administrator".
# Add a line of the following format:
If we were transferring DedicatedManagers.com to the IP 188.8.131.52, the line(s) would look like:
Now, as far as your local computer is concerned, the website is now located at the new server's IP address. (By the way, the power of editing this file is how a hacker can get you to visit a malicious version of a website without you knowing it.)
Another caveat to note is that since the website will be exactly the same on the new server as the old server (especially once it's running smoothly) you'll want to have a way to verify that you are seeing the new server when you load it in your browser. I like to make a small change to the header or footer of the website. Usually, I'll put "new server" in the footer somewhere.
Also, Chrome has great debugging tools that lets you disable the cache while the debugger is open and you can also view the IP address of the currently loaded page. In the screen shot below, I've opened the debugging inspector by right-clicking (anywhere) on the page and choosing "Inspect". Then I clicked on the "network" tab (you may need to reload the page if it's empty). Also note that even thought I have had "disable cache" checked, and other websites said it should clear them, 301 permanent redirects do not seem to be cleared. My solution was to open an "incognito window" which seems to not store 301 redirects between incognito sessions.
You can test with this setup for as long as you need to test using the actual website url and fix errors until the website is running smoothly on the new server. Just remember to take the entries out of your local computer's hosts file when you are done with the transfer.
Once your testing is complete and you've got the website running without any issues on the new server, you can log into wherever your DNS is controlled and change the IP address to the new server. The public traffic will switch over by the end of the TTL time set in your DNS. Years ago, the TTL value was typically set at 24 hours to reduce server loads. As bandwidth has increased and computers have gotten faster, we typically see a 4-8 hour TTL. If you want instant gratification, prior to your switch, change the TTL value for the DNS record to around 5 minutes (do so longer before than the TTL Value), so that when you perform the switch, all your traffic will come to the new server right away. This also has the advantage of being able to very quickly switch back if, for some reason, your testing wasn't thorough enough and you need to get the traffic back to the old server quickly while you fix whatever problems arose (Changing the TTL value should probably be s step in itself!).
If you've got the time to keep the old server running, wait a few days before deleting the files and your service on the old server. This will give you a chance to go back to the old server and solve and subtle issues that may arise. Typically an extra week is plenty.
After you've had enough traffic at the new server, and you are confident there are no issues, its time to delete your files on the old server and cancel your service.
In conclusion, this article was written to help point out the typical major tasks involved in transferring a website to a new host. This is not an all-encompassing guide. There are plenty of nuances to overcome. Please use this article as a starting point or initial framework to help guide your research into your endeavor to move your website to a new host. Realize, if your website is simple, some of the tasks above will not be required; they are documented to help those with a more difficult set up prepare to transition to a new hosting server.
We wish you the best of luck. Please feel free to contact Dedicated Managers should you need experienced professional help with transferring your website from one host to another.