How to transfer WordPress site from one server to another

This is one of the topics any web developer should know about and you’ll grow with any new website transfer that you make, because every server has its potential problems. I assume that you are the type of person who learns prior to any clicking and if so you have to get familiar with this procedure on WordPress support page. After that you may want to Google this topic looking for additional info that is shorter and easier for you to understand. Here is my first (successful) experience in step-by-step transfer of WordPress blog site from one server to another (with new domain).

WordPress blog that I transferred was using default theme twentyfifteen, it was hosted on HostGator and I transferred it to GoDaddy after buying new domain. For this example I’ll refer to those websites as www.oldsite.com and www.newsite.info so here is how to transfer WordPress site from one server to another.

1. Make a backup copy of www.oldsite.com

You can use FTP/SFTP client you are comfortable with, I am using FileZilla. Make sure you have downloaded all the files from www.oldsite.com to your computer (also include any hidden files like .htaccess). If you plan to keep the oldsite.com data forever you can make .zip or .rar archive of it.

2. Export your database from www.oldsite.com

The are many tools for this operation but I recommend phpMyAdmin which can also be found in hosting provider’s cPanel. Select the desired database from the left panel and click Export tab. Leave the default “Quick” option selected and click Go to download the database to your computer. Make .zip or .rar archive of this database since you will be modifying it later.

3. Upload robots.txt file on www.newsite.info

This is not essential step but it is useful if you want to prevent search bots to access and index your website while you’re migrating the data. Open you text editor and paste the following code:


User-agent: *
Disallow: /

Save the file as robots.txt and upload it via FTP/SFTP to the root directory of www.newsite.info.

4. Create a new database on www.newsite.info

I already described how to create new database in this post, so no need to repeat here.

5. Edit wp-config.php file

In your backup of www.oldsite.com open in text editor the file wp-config.php and locate the following lines:


define('DB_NAME', 'your_old_database');
define('DB_USER', 'your_old_database_user');
define('DB_PASSWORD', 'your_old_database_password');

Edit the database name, user and password according to your new parameters.

6. Install WordPress on www.newsite.info and upload old content from www.oldsite.com

Using the database created in step 4. install WordPress on your www.newsite.info but make sure that you install the same version that you had on www.oldsite.com. In my case it was version 4.2.3. Then use FTP/SFTP client to overwrite the data on www.newsite.info with the data that you downloaded from www.oldsite.com. You basically need to upload only the ‘wp-content’ folder, but in case you made any changes to core files earlier, you might transfer all files and folders just to be safe. Mind the file structure. This may take a while depending on how large your old site was, so be patient. Read a useful tip for uploading large content of data via FTP/SFTP.

7. Edit the database exported from www.oldsite.com

This can be tricky part of the process depending on how large your database is. In my case the website was young so altering the database took me fairly short amount of time. You may edit the database using your text editor and its function Find/Replace but bare in mind that errors may occur because of mass edit the URLs that, in some cases, are part of complex strings. Consider using some advanced software for this operation.

Those brave developers willing to use Find/Replace option in the text editor (at your own risk), you need to search for old URL of www.oldsite.com and replace them with new URL of www.newsite.info.

In my case there was 337 matches. I manually checked each and every one of them just to be sure on what is going to change. This is of course huge waste of time if you have several thousand entries, so I’ll repeat again, you may want to use some advanced software for this operation.

8. DROP the new database on www.newsite.info

This is very important part in order to avoid duplicating some pages and posts that were created with fresh installation of WordPress. So log into cPanel of www.newsite.info and go to phpMyAdmin, select your new database, click on Structure tab, click on Check All checkbox at the bottom of tables and select Drop from dropdown menu.

9. Import database from www.oldsite.com

While remaining in phpMyAdmin import the database that you modified earlier. Select the Import tab, use the Browse button to locate the database on your computer, leave all settings to default values and click the Go button at the bottom.

10. Clear browser cache

Not essential step but useful enough. Skip if you want.

11. Log into www.newsite.info/wp-admin

At this point you should be able to log into your website at new domain. The username and password are the same that you used on your old domain. In your Dashboard navigate to Settings ⇒ Permalinks and check if your option is set appropriately. Mine is set to Post name. Check if everything else is in its place and you’re done!

In my case I also had to relink the Header image in AppearanceBackground. Then I modified the main menu in AppearanceMenus, and footer.php file as well because I use custom info in the footer.

12. Delete/Modify the robots.txt file on www.newsite.info

You can delete or modify robots.txt file in the root directory of your new website. Learn more about this topic and if you need the robots.txt file after all.

13. Leave the redirection on www.oldsite.com to www.newsite.info

This step is optional but useful if you shared your posts on social networks and across the web, and I believe that you have. You can do this with .htaccess file. Learn about using the .htaccess file here. Simply open your file editor and paste the following code in the new blank text file:


RewriteEngine on

RewriteCond %{HTTP_HOST} ^oldsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldsite\.com$
RewriteRule ^/?$ "http\:\/\/newsite\.info\/" [R=301,L]

Save your file without name just with extension .htaccess and you’re done. Upload this file via FTP/SFTP to the root directory of www.oldsite.com. Make sure you alter the code according to your URLs. If the old domain is not going to be renewed, or it is reserved for deletion you can skip this step.

Appendix – Possible errors

If you get the following error message when first visiting your www.newsite.info page:

Warning: Cannot modify header information – headers already sent by (output started at //home/htdocs/wordpress/wp-config.php:1) in /home/htdocs/wordpress/wp-login.php on line 12

then you should try the following:

Open wp-config.php file in text editor and look if there is blank space (empty lines) before opening php tag:
<?php
and after closing php tag also:
?>
Delete the blank (empty) lines, save changes, reupload the wp-config.php file to the root directory of www.newsite.info and this should hopefully solve the problem.

If, on the other hand, you get a white page on your first visit, then logon to www.newsite.info/wp-admin and navigate to AppearanceThemes to check if your default theme is selected.

DISCLAIMER: I used the domain names oldsite.com and newsite.info only for the sake of this tutorial and ease of understanding the process described here. I do not own those domains and mentioning them in this post is for identification purposes only. Use of these domain names does not imply endorsement.

By janoshke

Web developer and IT consultant. Freelancer with full respect for OpenCart and WordPress. Gamer, (ex)drummer and parent.

2 comments

  1. On step #1, can you specify which directories should I back up? Essentially I have no idea whatsoever what file(s) to get.

    1. Hi,
      If you are logging to your server as a user then you most probably have the access only to the website root directory which is “public_html” folder on Apache servers. You can download ALL the files and folders from that directory to your local computer if you wish to keep it for your archive. This step is meant to be a precautionary step just in case something goes wrong in later steps so that you can always go back to safe check point. However, if you are backing up your site on regular basis and you already have your data stored in some safe location, you can skip this step.

      Cheers 🙂

Leave a ReplyCancel reply

Exit mobile version
%%footer%%