How Do I Migrate WordPress to a Different Domain Name?

Changing the domain name on an existing WordPress installation or staging a WordPress website at a different location may seem daunting at first. But it’s really quite easy to do. And I’ll show you how.

Use case #1:

You’ve purchased a number of domain names for your website. And you wish to assign another of your domain names as the main domain people see in the web browser location bar when they visit your website.

Use case #2:

Your client has asked you to update their existing theme but would prefer you not edit their live website. Staging the website in a subdirectory within the current hosting account will allow you to work with the existing theme in a safe environment.

Use case #3:

You would like to move your website to another web host, but test your website at the new host before pointing the domain name to the new hosting account.



Numero 1The process for making a backup of a WordPress website in preparation for a move to another hosting account or for staging purposes is rather straightforward.

Start by making a backup of your existing website files and database.

Backing up files and databases within cPanel is as simple as clicking Backup, then clicking two links:


Once you have a solid backup of files and database:

  1. Set up a staging subdomain within your web hosting account like, or use a different domain name entirely.
    1. If you are installing your WordPress site within a subdirectory on a cPanel server, click the Addon Domains button.
    2. If you are installing your WordPress site into the main directory on a cPanel server, click the Aliases button, and you’ll be all set in two clicks.
  2. Then install WordPress into the new account or directory.
  3. Rename the wp-config.php file for now.
    We are doing this so that when you recover your site files you do not inadvertently overwrite the newly set up wp-config.php file.
  4. Upload and extract your backup of files within to your staging directory.
  5. Delete the wp-config.php file you just copied over from the live site and rename the wp-config.php file renamed in (3) above back to wp-config.php
  6. The how to import a database part of the process can be a bit tricky the first time around.
    1. Since you already have a working wp-config.php in place and a working database in place, use your FTP or your web host’s file editor to view the contents of your wp-config.php in order to obtain the database name.
    2. Log into your PHPMyAdmin. Click on the database name at left. This will display a list of tables. Check all tables, choose the Drop option, then Go to drop all the tables.*
      *All you are doing here is removing the existing database tables in preparation for import.
    3. And finally, click the Import option at the top, Choose File, select that database you downloaded to your computer earlier, then click Go.
  7. If all goes well with the import you will have completed the initial staging setup process.


Numero 2If you are setting up a development site using a domain name different than the original, just add these two lines in gray to the top of your wp-config.php.file (below the line “<?php”), example:*



* The website covers editing wp-config.php fairly nicely, in case you are interested in reviewing the technical bits.


Then visit your migrated website.
99% of the time the two lines of text above are all you need to do!

WordPress Magic
“So what’s this magic going on behind the scenes” you may ask?

Ok, I’ll let the rabbit out of the hat. The guts of your WordPress settings are maintained in the wp_options table. All this magical bit of gray text in #2 above does is override your siteurl settings in your database.
Presto magico!



Below is an example of the above how to migrate your WordPress website to a different domain name.

The original website with website address:

Website migration demo 1


I copied the same website into a subdirectory of the same account for staging purposes, at:

and set the domain name to point to that subdirectory.

However, we had one obvious problem. Because the staging website was copied from any attempt to visit resulted in an immediate redirect back to the original domain.

Well, that’s annoying.
So, following step #2 above, I simply copy/pasted the two lines shown above into the top of my / file, like this:

wp-config.php example 1


The result? When I go to the new website address I had staged earlier within the directory:
/ appears nicely like this:

Website migration demo 2


Well, that about covers the basics of migrating a WordPress website to a different domain name by copy/pasting two lines of text.

If you have suggestions or additions to this WordPress staging or migration related article please be sure to email me anytime, jim at


One Response

  1. Everyone is well aware of the fact that, it is always recommended not to deploy/test any changes to a live site.

Please feel free to comment via WordPress, Twitter, or Facebook

Proactive WordPress Security Management for Pennies a Day™
© Copyright 2024™,™,
The Hack Repair Guy™, Hack Repair Guy™
Copyright and Trademark Statement | Privacy Policy

Call for website security help, (619) 479-6637.
Content Approved By Jim Walker, The Hack Repair Guy