1. Home
  2. WordPress Tutorials
  3. How to Move or Copy WordPress

How to Move or Copy WordPress

There are  several possible situations where you might want to keep an existing WordPress installation but change the URL where it loads from. If any task you want to do results in changing the URL used to visit WordPress, you’ll need follow these instructions carefully to avoid situations where the ‘old’ URL still gets used when you least expect it. Examples of a changing URL include:

  • Enabling or disabling SSL
  • Moving WordPress to another sub-directory
  • Changing the domain name of the website
  • Making a ‘staging copy’ of the site for development purposes
  • Switching back from the staging copy to the live version
Do you have a Plus hosting plan?

Our WordPress Plus Hosting  packages have additional tools to make this kind of migration much easier. Learn more here.

Preparation

Before any changes to the URL are done, there’s a couple things that need to be done first. Above all else, you need to make sure you make a new backup of the WordPress database! Several of the following steps in this article can potentially do permanent damage to your site! If the change you’re making involves moving the location of the WordPress files on the server to a new directory (such as a sub-folder move, or staging a site) back up the entire WordPress folder using FTP as well!

If you are copying content from one WordPress copy to another, back up both copies!

The next steps will depend on exactly what it is you’re trying to do.

Changing the WordPress URL

Only use these instructions if the location of WordPress on the server (in the file manager) doesn’t change. If you’re moving WordPress to a URL that uses a different directory on the server, skip to the next section.

In some situations, the location of the WordPress directory on the hosting server doesn’t change, but the URL used to visit your website does. This happens when you enable or disable SSL, or change the domain name of the website to another domain that points to the same folder, for example from the main domain of your hosting, to an alias domain. In these situations it is not necessary to back up the WordPress directory. All changes to WordPress will be in the database.

Start by logging into your wp-admin, and go to the ‘Settings’ > ‘General’ section. Both the WordPress Address and Site URL settings will need to be updated.

Using Permalinks?

If you use Permalinks, go to the ‘Settings’ > ‘Permalinks’ panel, and save your settings. You shouldn’t have to change anything, but saving your settings again will force WordPress to fix any errors in your .htaccess file related to the move.

Update Article Links

Once You’ve changed the base URL, WordPress will now default to that address for everyone visiting it, but many parts of your site including links embedded in your articles, and possibly your theme will still be using the old URL. Assuming you still have access to your wp-admin dashboard, you can use the Better Search Replace plugin to find and repair all those links.

Enabling SSL?

If all you’re doing is enabling SSL on your website, you may be able to skip this step and instead use a plugin like Really Simple SSL to make the necessary changes.

Moving Directories

These instructions are for permanent changes to the folder WordPress will run from. For Staging or Cloning, see the next section.

If the change you want to make involves moving WordPress to a different folder, such as switching WordPress to an addon domain, or moving WordPress to a sub-directory of your current domain, continue from here.

Start by logging into your wp-admin, and go to the ‘Settings’ > ‘General’ section. Both the WordPress Address and Site URL settings will need to be updated.

Don't Panic

Changing the URL here will cause your WordPress installation to stop working. We’ll fix that in the next step.

Transfer the WordPress Directory

The next step is to move WordPress to the new folder. You will need to copy or move all files for WordPress from its original directory to the new one used by the URL you set in the previous step. You can use the cPanel File Manager for this, or upload your backup copy of the site to the new location using FTP.

After coping your WordPress files to the new location and you can log into wp-admin again, it should be safe to remove the original copy of WordPress’ files. It’s not recommended to leave them in place for long as it may be confusing later.

Once you finish this step, you should be able to log into wp-admin at the new URL.

Using Permalinks?

If you use Permalinks, go to the ‘Settings’ > ‘Permalinks’ panel, and save your settings. You shouldn’t have to change anything, but saving your settings again will force WordPress to fix any errors in your .htaccess file related to the move.

Update Article Links

Once You’ve changed the base URL, WordPress will now default to that address for everyone visiting it, but many parts of your site including links embedded in your articles, and possibly your theme will still be using the old URL. Assuming you still have access to your wp-admin dashboard, you can use the Better Search Replace plugin to find and repair all those links.

This is rare but...

Some themes may have hard coded paths built into them that need to be updated to the new location. You may need to update the theme files directly to correct the paths.

Cloning or Staging WordPress

This will result in two copies of WordPress, each with their own database, and operating independent of each other. You will need your backup data for this. Not only is it for safekeeping but it’s also used to restore to the new copy. Unlike the other transfer methods in this article, We can’t touch the SiteURL ahead of time since we do not want to modify the original copy.

Create and Configure the Database

If you’re copying data from one WordPress installation to another (AKA “Staging”) then the destination database already exists, so skip ahead to importing the database backup.

First, we need a new database for the new WordPress installation. On Hostupon services, this is done through our cPanel. In the ‘Databases’ section, click on the ‘MySQL® Databases’ button.

Create a new database with a unique name.

Next, head back to the Databases panel, create a new database user. It helps if it has the same name as the database. Give it a random password, and copy it down for later.

Head back to the Databases panel one more time, and grant the new user full access to the new database.

Import the Database Backup

Now that your database is set up, it needs to be populated. You’ll need your backup copy of the original database for this step. In your cPanel, in the ‘Databases’ section, go to ‘phpMyAdmin’.

Once that’s open, select your database from the list on the left and click ‘Import’ from the top menu.

On the next page, click the ‘Browse…’ button and find your sql backup for the site. Once you’ve selected it, scroll to the bottom and click the ‘Import’ button.

Staging?

If you’re importing a backup database into a DB that already has tables, you may need to remove the existing tables first!

Update the wp-config.php File

Now we use the backup copy of the WordPress directory you created at the start. First, just to keep the original intact, make another copy of that backup on your computer. Then, in the newest backup copy of your wp-config.php file, we need to make a few changes.

First, find the database settings in the wp-config.php file and update three settings for the DB username, the Database name, and the password to the new ones you created in the previous steps.

Next, find the the ‘Add any custom values’ line, and add these three lines just below:

/* Add any custom values between this line and the "stop editing" line. */

//FIXME: do comment/remove these hack lines. (once the database is updated)
update_option('siteurl', 'http://your.domain.name/the/path' );
update_option('home', 'http://your.domain.name/the/path' );

Make sure you edit those two ‘update_option’ lines to include the actual new URL of your site, and save your changes.

Upload the Copy to the Server

Using the same method you used to back up the original site, upload the new copy (with the updated wp-config.php file) to the new location. If you’re uploading to a location that already has contents, I hope you backed that up first, since it needs to be overwritten.

If you did everything right, you should be able to log into wp-admin at the new URL.

Warning!

It’s very important that the copy of your site has your updated wp-config.php file If you upload the original unmodified wp-config.php file, both installations will try to use the same database, and that will really break things!

Successfully logged into wp-admin?

Now that you’re logged in, you should remove the extra lines you added to the wp-config.php file. They were only needed to update your database records the first time. You can use the File Manager in your cPanel to do this.

Using Permalinks?

If you use Permalinks, go to the ‘Settings’ > ‘Permalinks’ panel, and save your settings. You shouldn’t have to change anything, but saving your settings again will force WordPress to fix any errors in your .htaccess file related to the move.

Update Article Links

Once You’ve changed the base URL, WordPress will now default to that address for everyone visiting it, but many parts of your site including links embedded in your articles, and possibly your theme will still be using the old URL. Assuming you still have access to your wp-admin dashboard, you can use the Better Search Replace plugin to find and repair all those links.

This is rare but...

Some themes may have hard coded paths built into them that need to be updated to the new location. You may need to update the theme files directly to correct the paths.

Updated on August 29, 2023

Was this article helpful?

Related Articles