If you run a website for any length of time, chances are you’ll want to move your site and email to a new web server at least once. For example:
- You may have exceeded the bandwidth allowance or disk quota of your current server (good for you, your site’s getting more popular!)
- You might be fed up with your current host’s downtime or poor technical support
- Your old hosting company may be going out of business (an all-too-common occurrence unfortunately)
Let’s assume you’ve chosen a new Web hosting company and you’re ready to transfer your website. Broadly speaking, there are 2 ways that you can move your site across:
In this step-by-step article I’ll try to give a general overview of the moving process, and look at some of the pitfalls to avoid along the way. I strongly recommend reading this whole article before you start the moving process.
Here’s a brief overview of the steps:
- Back up your site. Make a backup of your site files and data on your own computer.
- Set up your web space and email on the new server. Prepare your server to handle your site and email accounts.
- Upload your site. Upload the backup you made in Step 1 to your new server.
Check the site works. Visit your site on the new server and make sure everything works.
- Configure your email software to check mail on both servers. This ensures you don’t lose any email messages during the transfer.
- Shut down interactive areas on your old site. This optional step prevents visitors adding any new content to your old site during the changeover.
- Redelegate your domain. This moves control of your domain to the new nameservers, and gets everyone looking at your site on your new server.
- Retest your site and email. Now that the new server is live, check that everything works as it should.
- Shut down your old hosting account. Once you’re confident that everything is working properly you can shut down your old web hosting account.
1. Back up your site
Back up all your current site files and data to your own computer now. (In fact it’s a good idea to back up your site regularly anyway.) That way, if anything goes wrong, at least you have your own copy of your site.
- If your site just has static HTML pages then backing up is easy: Simply FTP the site’s document root folder (usually called
mainwebsite_html) to your PC.
- If you have server-side scripts (such as Perl or PHP) then make sure you back these up too. Often these are in the document root folder along with your regular HTML files; however they might be in another folder (such as
If your site has a database back-end (such as MySQL) then you’ll need to back up that data too. There are several ways you can do this. If you have SSH (shell) access to your current server then you can run a command such as:
mysqldump -u username -p --lock-tables database_name > database_name.sql
Then use FTP (or another similar method) to download the
database_name.sql file to your PC.
Alternatively, if you have access to phpMyAdmin (a Web-based MySQL admin tool) then you can back up your MySQL database using the Export tab.
2. Set up your web space and mailboxes on the new server
Your new hosting company may have set up your web space and email accounts for you. If not then you’ll need to set these up yourself.
The easiest way to set up your web and email is to use the control panel that comes with your hosting account. (Most servers come with some sort of web-based control panel; popular control panels include cPanel and Plesk.)
Make sure you set up email accounts, or email forwarding, for all of the email addresses you currently use.
3. Upload your site to the new server
Now that your web space is set up, you can transfer your website’s files to the new server. This process is pretty much the opposite of Step 1:
- For static sites, just upload the site files and folders to the new server’s document root folder.
- If you have scripts, you may need to upload these to a different folder. You may also need to set permissions on the script files for them to run correctly, and also update any paths in the script config files to reflect the folder structure on the new server.
If your site is database-driven then you’ll need to upload the database backup you created in Step 1, then import the backup into your new database. For example, with MySQL you can run a command such as:
mysql -u username -p database_name < database_name.sql
If you’re using phpMyAdmin on the new server then you can import the data file using the Import tab. However, be careful with this approach, because many web servers limit the size of uploaded files, as well as how long PHP scripts can run. If your data file is very large — say, greater than 10MB — then you may run into problems. In this case, use the command-line technique above, or ask your hosting company to import the data for you.
4. Check the site works
You’ve moved your site to the new server, but it’s not yet live (since the DNS hasn’t been transferred). Now is a good time to test your site to make sure everything works.
To do this, you need to tell your PC to look at your new server rather than the old one when browsing your site. You can do this temporarily as follows:
- If your PC runs Windows: Edit the file
C:WINDOWSsystem32driversetchosts. You can do this by clicking Start, then Run, then typing notepad C:WINDOWSsystem32driversetchosts into the Run box, and clicking OK.
- If you run Mac OS X or Linux: Edit the file
/etc/hostsusing your favourite text editor. You’ll need root privileges to do this. For example, in Mac OS X, open the Terminal app then type: sudo pico /etc/hosts.
Once you’ve opened your
hosts file, add the following line to the end of the file:
ip address domain name
where ip address is the IP address of your new server, and domain name is your website’s domain name. For example, if you were moving your site
www.example.com to a web server with an IP address of
220.127.116.11, you’d add the line:
Now save the file and quit the editor. You can test that your change has taken by opening a terminal window (Start > All Programs > Accessories > Command Prompt on Windows) and typing:
If you see your new server’s IP address in the output then the change worked.
Now open a browser and enter your website’s URL in the address bar. This will display the site on your new server. Visit all areas of your site and check everything works. If you get any server errors then you may need to look in your new server’s error logs for details (ask your hosting company for advice). Check for common problems such as incorrect paths, incorrect permissions, and missing files/folders.
5. Set up your email program to check mail on both servers
Since it can take a couple of days to change over your domain to point to your new email server, there will be a period when some people are sending email to your old mail server while others are sending email to your new server.
Therefore it’s a good idea to get the email application on your computer to check both mail servers for new mail during the transition period. Follow these steps:
- Change the current “mail server” setting from a hostname to an IP address. Open up your email program and find the settings for your current mail server (this will probably be in a “mail accounts” section in the preferences). Chances are that the “mail server” box shows the hostname of your old mail server (e.g.
mail.example.com). Change this to the server’s IP address instead (e.g.
18.104.22.168). This ensures that your mail software continues to check the old server, even once the domain has been switched over.
- Add the new mail server. Create a new mail account in your mail software and add the details of the new mail server. Again, use the server’s IP address instead of its hostname, so that you know it’s checking the right server.
6. Shut down interactive parts of your site (optional)
Once you move your domain (see the next step), it will take up to a few days for everyone to start using the new server. If your site features areas where visitors can interact and add content (forums, blog comments, shopping carts, and so on) then you run the risk of some people adding content on the old site while others add content on the new site. When the domain has finally moved then the new content added to the old site will be lost (unless you manually import it into the new site, or ask your visitors to re-post their content!).
If you only get a blog comment or two a day then you may not care. However, if you’d rather visitors didn’t add stuff to the old site during the changeover, you might want to shut down just the areas of your site where users can add new content, such as forums, blog comments, and registration forms, and put up a holding page informing them that these areas will be back soon.
7. Redelegate your domain
Redelegating your domain means telling everyone on the internet to use your new hosting company’s nameservers when looking up your domain, rather than the old nameservers. Since the new nameservers point to your new web server, this process effectively tells everyone to view your site on the new server.
To redelegate your domain, follow these steps:
- Check your new nameservers. Find out the hostnames of your new nameservers. Usually there are 2 nameservers, and they’ll have hostnames along the lines of
ns2.example.com. Your new hosting company will probably have sent you an email with this information. Also you might want to double-check with the hosting company that these nameservers have been properly set up to host your domain. (Usually this happens automatically when the hosting company sets up your web space.)
- Login to your registrar’s website. Your registrar is the company you registered your domain name through. It may or may not be the same company that currently hosts your site. Usually the registrar sends you a username and password that you can use to login to their site to update your nameservers.
- Change the nameservers. Find the option to edit/change your domain’s nameservers. Change the nameserver entries to the hostnames of your new company’s nameservers.
- Wait. Sit back, relax, and wait (usually around 24-48 hours) for the redelegation to propagate around the internet.
Congratulations — your site is now live on your new server!
8. Test everything works
Once your new server is live, check again that all aspects of your site work properly — especially interactive areas of the site, such as contact forms, user registrations, blog comments, and forums.
It’s also a good idea to send various test emails from and to your email accounts, as well as from and to external addresses, such as Yahoo! Mail or Gmail. If an email bounces, take a look at the headers of the bounce message to identify the problem. (If you can’t work out what’s wrong then forward the bounce message to your hosting company for investigation.)
9. After a few days, shut down the old hosting account
Once a few days have passed, chances are good that everyone will be using your new server rather than the old. You can double-check this by inspecting your site access log and email log on the old server (if you have access to them). You might still see the odd search engine crawler visiting the old site for a time, and the odd spammer sending mail to your old email server. On the whole, though, you should see very little, if any, activity.
You can now safely shut down the old hosting account or server. You’ll also want to open your email program and remove the mail account for your old mail server, and change the new mail server’s IP address back to its hostname.
If all has gone well then you’ve now successfully moved your site and email from your old hosting company to your new one. Well done!