Moving a WordPress

The scenario is that you have a fully functional WordPress, somewhere, and it is a different name, and you want to transfer it.
An example of one I have done was a new site being build as and it is going to replace
I have even done this between servers, and on the same server.

Step 1

  1. Update all plugins.
  2. Update all themes.
  3. Update WordPress.
  4. Make a backup.
  5. Better still, if you have access to the CLI, make a mysqldump of the database (see below) and a zip of the documnet root.
  6. If the transfere is between servers, download both files to your local computer.

Step 1.1

Making a MySQLdump.

mysqldump -umysite_wp2 mysite_wp2  -p'S.2TgD7jpNLtAvhgWLE49' > 05092021.sql

You find the user, site db, and password in wp-config.php

Step 2 Find & Replace

I use emacs on a Linux machine to do the find and replace.
The find and replace command is ctrl-shift-alt-%

We need to find and replace

  • and replace it with
    • This makes sure all redirects are corrct to the new url
  • /home/user/ and replace it with /home/user/public_html
    • This makes sure the document root is correct.
  • and replace it with
    • This makes sure any email addresses have been changes to the correct domain name
  • Search on, and see what you find you may have to do
    • and replace it with

Step 3 Move directories

  • Up load the SQL file and the ZIP file to your new staging area.
  • I move the existing public_html to old.public_html.
  • Unzip the zip file to a hold directory.
  • Create a new public_html with the correct ownership and permissions
drwxr-x---.  7 myname nobody      4096 Sep  6 07:02 public_html
  • Copy wp-config.php from old.public_html to public_html replacing the one from the old staging site
  • Copy the files from the Zip Hold area to public_html
  • Make sure they have the right ownership, myname.myname, and permissions.

Step 4 import the SQL archive.

Using the correct settings from the wp-config.php file run:

mysql -umysite_wp2 mysite_wp2  -p'S.2TgD7jpNLtAvhgWLE49' < 05092021.sql

This is the reverse of what we did above.
There should be no errors and the command line should just drop down one line.

Step 5 plugins

Plugins should just work.

However, I have found one issue with Wordfence. There is a setting that want to point back to the old site.

; Wordfence WAF
auto_prepend_file = '/home/oldsite/'
; END Wordfence WAF

And change it to where the new document root is.

; Wordfence WAF
auto_prepend_file = '/home/mysite/public_html/wordfence-waf.php'
; END Wordfence WAF

And everything now works.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.