Skip to main content

Moving WordPress with a different domain to another web host

Search-Replace-DB-master
Posted by admin on 23rd Jul 2017

If you have been working on many WP sites, at some point you may encounter having to move a WP site to another host with a different domain name. Or more commonly, working on a local development build and need to migrate to production (live site).

You will noticed WordPress will not automagically alter all your URL paths to match your new domain (including the site domain URL). This process would have to be done manually.

This is problematic if you are not comfortable with SQL DB queries. 

To make your life easier, there is a script that takes care of this for you with a little work on your behalf.   

The script is called Search-Replace-DB on Github. 

Here is the process to follow:

  • Transfer all your complete existing WP site to your web hosting server
  • Export your existing site DB. You can install this plugin to export your DB: https://wordpress.org/plugins/wp-db-backup/
  • Setup your new DB on your web host server (take note of your new DB login credentials you have created. You will need this for the next step below) and import your existing DB
  • Once your existing site has been fully uploaded to your web host, open up wp-config.php file and update your DB login credentials as shown below:
define('DB_NAME', 'Enter your DB name here');

/** MySQL database username */
define('DB_USER', 'Enter your DB user here');

/** MySQL database password */
define('DB_PASSWORD', 'Enter your DB password here');
  • Download Search-Replace-DB and unzip the content. Upload the the folder 'Search-Replace-DB-master' to your web host server and place it inside your WP installation directory so it is a sub directory.
  • In your web browser, navigate to this sub dir, ie https://{your-domain-name}/Search-Replace-DB-master. This should bring up the Search-Replace-DB page
    Search Replace DB
  • Wordpress usually stores absolute paths so this is what you need replace, as well as the domain URL.  
  • You need to find out what your old and new absolute path is to be replace. For example, if your old path is /home/{username}/public_html/ and new path is /home/{new-username}/public_html/ then in the replace field, enter:
    home/{username}/public_html

    and in the with field, enter:
     

    home/{new-username}/public_html

    Do not just enter the {username} alone since this name may occur in other DB tables you do not want to replace.

  • Click 'dry run' button to see the output and compare what has been replace by clicking on 'view changes' link. 'Dry run' will not begin to replace the DB entries so it will give you a chance to see what will be replace. 

  • If it all looks good to you, you can click 'live run' to actually start replacing the DB entries.

  • Now you need to replace the site domain URL. So in the replace field, enter your old domain and in the with field, enter your new domain name (best to use the full domain URL, for example: https://example.com). Do a 'dry run' again to see the results. If ok, do the 'live run'.

You can browse to your new domain URL in your web browser and see if it is working.

At this point, I ran into an issue. For some reason my siteurl DB field which holds my site domain URL was not replaced with the new one. If this happens to you too, you can try and replace it again with Search-Replace-DB script or manually change this in your DB by following this guide: https://codex.wordpress.org/Changing_The_Site_URL (go to the section with title heading: Changing the URL directly in the database).

If everything is now working, you can delete the Search-Replace-DB script. There is a 'delete me' button, just click this button to remove it. 

 

Back to top