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
htdocs
,public_html
, ormainwebsite_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
cgi-bin
).
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/hosts
using 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 5.6.7.8
, you’d add the line:
5.6.7.8 www.example.com
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:
ping www.example.com
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.1.2.3.4
). 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
ns1.example.com
andns2.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!
desibird says
in-order to move any (php based) content management system, all we need is: MYSQL Export file, and config.php file. This is related to Joomla, wordpress and drupal.
firstly, export the MySql file from your phpmyadmin. Inorder to know, how to do it:
Simply log into phpmyadmin, click on EXPORT, default is SQL radio button, which is good, now click the “save-file-as” box, and then you are done.
upload all the files to desired folder and upload the sql file into new database. (it can be done by just logging into phpmyadmin and using import button.)
Now, change the db_username, db_password and db_name to the current db details.. and you are done!!
Your cms site is now up and running from a new server…!!
Any questions please, reply back!!
matt says
@desibird: Thanks for posting your tip. ๐ phpMyAdmin can be pretty handy! Though, as mentioned in the article, this trick doesn’t always work with large databases. In that situation you need to use the command line method instead.
Cheers,
Matt
desibird says
@matt: i’ve tried it plenty times and touch-wood nothing wrong has happened till date.
well, when uploading/importing the database, I’d go with your suggestion of command line method..
Its an overall best way to do any thing via command-line/terminal.
will start writing posts on wordpress and will also upload the templates I’ve designed, so elated-scribers can use it..!!
laura28 says
Hey Matt, great article!!!! You have shown very simple and easy steps for the users and website holders. Great going. It doesn’t seems that u r a beginner. Keep it up.
olidev says
Manually installing and setting up OS and stack for php site looks quite a long and tiring process. Why not instead use platform, like Cloudways, for hosting php in one click? Using this platform, we can quickly launch a server without any manual configuration and deploy php site on it through ssh or git.