Snapcreek

Snap Creek Software

Common Sense WordPress Solutions

Manually Move WordPress

How to Manually Move a WordPress Site

There are times when you may find yourself needing to move a WordPress site to a new domain or host. Most times you’ll be able to perform the WordPress migration by using a plugin such as Duplicator Pro, however there are times when a plugin may not be feasible or available due to site policy or perhaps personal preference.

In these instances, you’ll migrate WordPress manually. This article explains how to do that.

WordPress Migration

We’ll cover two scenarios:

  1. Move WordPress to a New Host. You may be interested in moving hosts, perhaps for performance reasons.
  2. Move WordPress to a New Domain. You may want to move your site to a new domain or duplicate a site for purposes of creating a new site from a base site.

Although the steps required for the two scenarios are very similar, they do diverge. The places where the procedures are different will be clearly indicated.

Steps to Move WordPress Site

move WordPress site: export database1. Export Database

The first step is to export the data in your existing database to a SQL file.

Using phpMyAdmin (web hosts):

  1. Select the existing site’s database.
  2. Click the Export tab.
  3. Select Quick for the export method
  4. Select SQL for the format.
  5. Click Go.
  6. Save the file to your local machine.
  7. Zip the file if you are migrating to a web host that uses phpMyAdmin.

Using MySQL Workbench (localhost):

  1. Select database to export.
  2. On the Server menu, click Data Export.
  3. Select database.
  4. Select Export to Self-Contained File.
  5. Click Start Export.
  6. Zip the file if you are migrating to a web host that uses phpMyAdmin.

transfer files

2. Transfer Files

We’re going to need to transfer the files from the source location to destination location. If you are moving to the same host this would just be a simple copy using the host’s File Manager.

To transfer files between sites:

  1. Purge any all files in the destination (optionally back up these files first).
  2. Zip the source machine’s WordPress directory using the File Manager on the server or localhost.
  3. Download the zip file to your local development machine via (S)FTP or the File Manager .
  4. Upload the zip file to the destination machine via (S)FTP or the File Manager to the directory that will contain site.
  5. Expand the zip on the destination machine using the host’s File Manager.

3. Create Database

migrate WordPress site: export database

Now we’ll create a database that will store the new site’s data.

Using cPanel:

  1. Click MySQL Databases.
  2. Supply a database name.
  3. Click Create Database.

Using MySQLWorkbench:

  1. Connect to the appropriate database server.
  2. Click the Create A New Schema button.
  3. Populate name.
  4. Click Apply.

4. Create User

moving WordPress: create db userNow we’ll create a user that has rights to the database created in step 3.

Using cPanel:

  1. Scroll down to the MySQL Users section
  2. Supply a user name and password.
  3. Click Create User
  4. In the Add User to Database section, select the database and user.
  5. Click Add.
  6. Add the following privileges: Select, Insert, Update, Delete, Alter, Create, Drop and Index.
  7. Click Make Changes.

Using MySQLWorkbench:

  1. Click the Users and Privileges link under the Management section in the Navigator.
  2. Click Add Account
  3. Populate user information.
  4. Click the Schema Privileges tab.
  5. Click Add Entry.
  6. Click Selected Schema.
  7. Select the database.
  8. Select the following privileges: Select, Insert, Update, Delete, Alter, Create, Drop and Index.
  9. Click Apply.

5. Import Data

Now we’re going to import data into the database we just created.

Using phpMyAdmin:

  1. Select the database created in step 3.
  2. Click the Import tab.
  3. Click the Choose File button in the File to Import section.
  4. Click Go.

Using MySQLWorkbench:

  1. Click Data Import/Restore under the Management section in the Navigator.
  2. Click Import from Self-Contained File.
  3. Choose the file.
  4. Select database in Default Target Schema dropdown.
  5. Click Start Import.

6. Edit wp-config.php

There are two main types of data that need to be changed in the wp-config.php file after a move. One is the database connection information and the other are variables and settings WordPress core and plugins depend on.

To alter the wp-config.php file:

  1. Find define(‘DB_NAME’, ‘{old_db_name}’) and replace {old_db_name} with the name of the database created in step 3.
  2. Find define(‘DB_USER’, ‘{old_db_user}’) and replace {old_db_user} with the name of the user created in step 3.
  3. Find define(‘DB_PASSWORD’, ‘{old_db_password}’) and replace {old_db_password} with the password of the user created in step 3.
  4. Search the file for any instances of your old domain name and replace with the new domain name.
  5. Replace any instances of the path of your site on the old server with the path of your site on the new server (e.g. /home/myoldhostlogin/public_html => /home/mynewhostlogin/public_html)

7. Edit .htaccess

.htaccess files often need to be changed when you move hosts. Note the particulars of this only apply if you are running Apache on the destination server.

  1. Copy the existing .htaccess to .haccess.orig
  2. Edit a new .htaccess file.
  3. If your permalink structure was the default, save the empty file.
  4. If your permalink structure was non-standard make your .htaccess look like the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# Note: The below line needs to be RewriteBase /{subdirectory}
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Note: The below line needs to be RewriteRule ./{subdirectory}/index.php
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

The comments regarding {subdirectory} indicate that if your website is not in the root of the domain that you need to alter them. (e.g. http://mynewdomain.com/mynewsite/ => RewriteBase /mynewsite and RewriteRule ./mynewsite/index.php)

8. Swap Database Values

Perform this step only if you are changing domains. Otherwise, continue to step 7.

We now have the files and data from the source site in the destination site.  However the database contains references to the old site URL that will need to be swapped with references to the new site URL.

The easiest way to do this is to use a special Search and Replace script. This script searches for a value in a database and swaps it with data from another while also performing serialization and deserialization.

To swap values using the interconnect/it Search and Replace script:

  1. Save the search and replace script to a subdirectory on your website (e.g. ../public_html/search)
  2. Browse to the script directory (e.g. http://mynewdomain.com/search).  Upon start the script reads the database connection values from your site’s wp-config.php so if you experience an error fix the wp-config.php.
  3. In the “search for” text box enter your old site URL with no slash on the end. (e.g. http://myolddomain.com)
  4. In the “replace with” text box enter the new site URL with no slash on the end. (e.g. http://mynewdomain.com)
  5. Click dry run and correct the search or replace text if necessary..
  6. Click live run.

moving wordpress site: search and replace WordPress database values

9. Preview Site

To see what your site will look like running on the new domain before you’ve switched servers, edit your hosts file to map the domain of the new host to the IP address of your server. This is done so you can view the site as if the domain name change had propagated before you’ve made changes in your registrar.

To map new domain to IP before DNS propagates:

  1. Add the mapping of your server’s IP address to the hosts file (e.g. 123.123.123.123 mynewdomain.com). Operating system specific instructions for editing the hosts file.
  2. Flush the DNS mapping of your machine. This is done differently on different operating systems:
    1. Windows: From an administrator command type “ipconfig /flushdns.”
    2. OS X: Instructions
    3. Linux: Instructions 

Finally, verify things looks good by browsing to your site using the new domain name. (e.g. http://mynewdomain.com)

10. Resolve Problems

You may experience miscellaneous problems after a manual move. The following are some ideas that may help:

  • You may also need to swap URLs in the functions.php depending on your customizations.
  • Turn on debugging to the display or to the error log and investigate errors or warnings.

11. Switch Domain Servers

Perform this step only if you are changing hosts. Otherwise, continue to step 10.

After you’ve previewed the site and seen that it looks good you can now set the domain servers.  The new domain’s name registrar will have instructions for how to do this.

It Takes Work to Move a WordPress Site

Although it takes a bit of work, moving a WordPress site isn’t that bad if you have time and patience. In the instances when you don’t have the time or are experiencing problems you may want to try an alternative to the above procedure, such as letting the WordPress migration plugin Duplicator Pro do the move.

Credits: Abstract vector created by vectorjuice – www.freepik.com

Scroll to top