Migrating to new web hosting

No, I’m not moving to new hosting company this post is for your easier migration. For some reason your current web hosting is not appropriate anymore, either by price, availability or supported services. I won’t get in any discussions like “this hosting company is better than this one” it’s up to you to decide where you want to migrate. I often see lot’s of new and inexperienced webmasters that are moving for the first time, the horrors they are facing, web portals not functioning after migration, unsatisfied website users (and webmasters), pain and agony of migration, usually resulting to be first and last migration in sites lifetime. Usually it doesn’t have to be that stressful. Here you will find some helpful tips & tricks for easy & painless migration of your linux based hosting package to new provider

Before we begin

You must be aware of some things. There are many kinds of hosting companies ranging form ones with very low prices and huge amounts of resources they offer in packages and ones with high prices, low resources and services. Both have their advantages and disadvantages it’s up to you to carefully wage and thoroughly study both.

Don’t fall for advertisement like unlimited package space and traffic, nothing in this world is unlimited! All those resources are carefully limited in providers SLA and AUP probably stating that site will be terminated if it starts to abuse servers resources, so don’t be surprised if your site suddenly stopped working.
If you want quality service consider hosting with smaller and more expensive package, as they usually tend to have better and more prompt support (this doesn’t have to be entirely true, explore a little for yourself).

Step 1. Define what you want

By now you probably have your reasons why you are migrating, and I will presume you waged new provider cons and pros. But what most of the people tend to forget is new hosting compatibility with your site and vice versa. If you are migrating to dedicated server then you should define your exact needs to your new provider. Here I’m talking about technical specs like database versions, php versions, configurations etc. Have in mind if you are moving to shared hosting, those need may not be met and provider will most likely not change current working configuration for other 200-300 sites because of your site.

What you should be interested with?

I will assume we are migrating Php + MySql based website on Linux hosting. First of all you should be interested in php version.

PHP

Try to stick with your current working version (unless your reason for migration is to get newer version). Make an phpinfo file on your current host, simple

< ?
phpinfo();
?>

in empty php file should suffice. Inspect your current version, and running config. Try to match that running config on new host. Some options may not be the same and may not have significant effect on your site performance and availability, but if new hosting don’t have some custom “non standard” php modules in running configuration, and your site relies on them then that may be a problem.
For example: your site makes database connections trough pdo mysql extension in php, and your new provider don’t have it in php running config, than it’s safe to say your site will not work on new host.

Some of those shortcomings in php configuration can be solved with some workarounds, it’s up to you how much time you wish to spend rewriting your current code.

There are also some differences in versions of php, some OOP code may work on php4 as a side-effect, and it may not work in php5.

How is php run? As cgi, suphp, or as apache module? Although I support new ways of running php as suphp since it will liberate you from all those permission problem, fact is some sites and code just won’t work with php run like cgi or suphp.

MYSQL

As with php, you should try to match the current running version of mysql with new providers mysql version. Usually upgrading to newer version will bring you only good stuff but there are some differences in sql syntax and behavior so you may end up in rewriting your code. By any means try to avoid downgrading, especially between different branches (mysql5 and mysql4). Although it may work, it will most certainly bring you more headache than any good.

APACHE

Is your site compatible with new apache version, is new apache supporting all my needs… caching, rewriting, etc.

Step 2 – Migration preparations

First of all give yourself time. Don’t lead yourself in situation where you have to migrate your site in 2-3days period, lot’s of it can still go wrong even if you found the perfect new host. Extend your site hosting on old host at least for another month so it overlaps with new hosting.

Get all the relevant information

By relevant I’m referring to current host names, IP-s, name servers, temporary cpanel and FTP access addresses. You may wonder why? When your domain name is moved to new hosting provider only way to connect to old host is by it’s IP-s and temporary server addresses. How to obtain those information?

First and easy way is to ask your current provider, if they ain’t as cooperative then it’s up to you. There are many web services that can tells you a lot I’m very found of http://www.robtex.com/dns/ type your domain name and it will give you much information about current name servers (under NS record) your mail handling servers (under MX record) and ip of your webserver (under A record).
You can also get those informations from command-line of your browser by typing nslookup
and then setting query type with set type=A (for A record), and so on..
for example:

branko@imoen:~$ nslookup
set type=a
toic.org
Server:		192.168.0.1
Address:	192.168.0.1#53 

Non-authoritative answer:
Name:	toic.org
Address: 89.201.164.195

Now when you have ip addresses when the need arises you can use then to login on old host, just use A record ip for your ftp hostname or in url for accessing cpanel.

Also if you have custom MX (google aps mail handling for example) records meaning some other server is handling your mail, remember to mention this to new provider so they can update MX records on their hosts.

Preparing domain for migration

After changing name servers to new hosting provider there will be at least 24-48h period when your site will be available on both hosts depending on DNS propagation trough various ISP. In that period it may be some anomalies usually associated with highly dynamic sites. Anomalies will be noticeable like missing forum or blog posts and comments, double posts etc… You can avoid this in two ways.

First way is to ask your old hosting provider to minimize Ttl values for your domain to let’s say 10 min or less, then you need to wait 24-48h for new ttl to propagate trough Internet. After that period when you change name servers for your domain, changes should be visible trough all Internet service providers in matter of minutes (depending on your ttl value).

Second way is to temporary put all your forums, commenting software and other dynamic managed content on old host in some sort of maintenance mode thus preventing any updates. This will prevent any missing content on new host.

Also don’t redirect your domain to new host until you are absolutely sure everything works perfectly on new host.

Step 3 – Moving the content

If you are lucky enough that both old and new hosting use same cpanel software you can ask new hosting provider simply to move all your content trough cpanel automated scripts. In this way you will retain all your databases, files, mails, passwords and other settings just the way they are now on old host (assuming of course that new provider have met all your needs discussed above).

If your not comfortable in giving your current passwords to new provider (which they will need to do the transfer) you can simply do a full backup trough cpanel on old host, upload it to new host and ask new provider for account restoration from full cpbackup/cpmove archive you just uploaded.
If you aren’t that lucky to have same cpanel versions on both hosts then you have the task of migrating content manually.

First of all create all the necessary mail accounts on new host so that mail doesn’t bounce back to sender when you finally do change name servers.

Second step is mysql database migration. Although almost all providers nowdays have phpmyadmin on clients disposal I strongly discourage you for using it for migration, especially if you have custom charsets. Instead use mysqldump or scripts like: http://www.hotscripts.com/Detailed/25634.html
Mysqldump will require you to have SSH access to both hosting providers, if you don’t then use this backup script.

To make database backup using mysqldump simply type in shell

mysqldump -u mysqluser -h mysqlhostnam -p mysqldatabase > mysqldatabasebackupfile.sql

it will then prompt you mysqluser’s password.
Ofcourse you must replace mysqluser, mysqlhostname and mysqldatabase with your actuals usernames hostnames and databases.

To later import this backup on new host you will simply type in shell:

mysql -u mysqluser -h mysqlhostname -p mysqldatabasename < mysqldatabasebackupfile.sql

This way you will preserve all your custom charsets and dump won't be tainted.

Now all you need to do is copy the files.

If you have ssh access to both old and new hosting provider you can use it to copy data server to server if not, you will have to download data from old host to your computer and re upload it to new host.
In both cases I strongly recommend that you make some type of compressed archive since it will greatly speedup transfer progress.

If you do have ssh access follow this:

On old host navigate to your www root folder usually www or public_html

bash# cd public_html
 

create an archive:

bash# tar czvf mysite.tar.gz *
 

copy the archive to new host

bash# scp mysite.tar.gz  username@hostname:/home/username/public_html/
 

Here you will have to use new hosts user name, in host name don’t type your domain name since you will probably end up on same server from which you are copying, use ip address or new server’s host name.

On new host navigate to your www root folder

newhost# cd public_html
 

extract the archive

newhost# tar zxvf mysite.tar.gz
 

Voila! Your content is now on new server.

Step 4 – Verify

Don’t jump the gun just yet. Verify that everything works. You may need to update some absolute paths in your scripts config files if they aren’t the same as on old host. Same applies for mysql connection strings.

After all of that is done you will want to see the site with your eyes. Since domain name is still on old host you will have to use few tricks.

  • Install the showip plugin for firefox or similar one for browser you are using.
  • Put ip of new server in your hosts file like this:

      newip domainname.com www.domainname.com
    
  • You will find hosts file in /etc/hosts (on linux) or %SystemRoot%\system32\drivers\etc\ (for windows, replace systemroot with windows install dir)
  • Restart your browser and then type in your url. If you installed showip or similar plugin you should now see that it says ip of your site is on new host.
  • Examine your site and verify everything is ok.
  • After you are done, remove that newly inserted line in hosts file

This little trick will allow you to get a sneak preview how will your site look on new host. If everything is as it should be you can change your domain name servers to new hosting company, if in doubt just ask them which ones.

If anything went wrong for some reason you still have those informations about old host gathered in step 2 right?

You can use them to make a fresh copy of content, compare the differences or in worst case scenario to change domain name servers back to old hosting company.

Related posts:

  1. Dealing with memory limits
  2. SSH basics
  3. Fetching remote content with curl
  4. SSH port forwarding

  1. Of course web hosting migrating is a difficult process. But you can always ask a web hosting company for help. As for us we are always willing to help our potential clients.

  1. No trackbacks yet.