WordPress Copy a Website

If you've got the perfect WordPress website and want to copy it, here's how to do it. Perfect here is more focused on the backend and administrative stuff, not the content of the site. IE, Plugins, custom themes, and other customizations, etc.

It's a lot like 'moving' a WordPress website, but with some extra stuff.

The key is chaning the Domain Name from the old to the new.

...but First

If using WordFence or any sort of Caching Plugin like WP-Rocket, etc., disable those Plugins before copying the database or files.

Copy Files and Database

cp -ax WhatEverSourcePath WhatEverDestinationPath

mysqldump -u root -p WhatEverSourceDatabase > WhatEverFileName

mysql -u root -p WhatEVerDestinationDatabase < WhatEverFileName

Modify Domain Name in Database

In the wp_options Table, using phpMyAdmin, change the siteurl and home option_name to the new Domain Name.

Then use the Better Search and Replace Plugin: Enter Old and New Domain Names, Select Tables by clicking the Top Item in Select tables, then scrolling to the bottom, holding the Shift Key and clicking on the Bottom Item, Case-insensitive: UNchecked, Replace GUIDs: CHECKED, Run as Dry run: UNchecked

Modify Domain Name in Files (Don't do this until all the database replacements have been done)

Utilities (for Windows)

  • Advanced Find and Replace (costs $)
  • Find and Replace (Free, with donation request)
    • Suggested Exclude Mask: *.dll, *.exe, *.png, *.jpg, *.webp, *.bcmap, *.z, *.tmp, *.pdf, *.zip, *.pack, *.idx, *.swf, *.ORIGINAL
    • Suggested Settings: Case Sensitive (turn it ON)

Utilities (for WordPress)

  • String Locator Plugin

Command Line (Cannot find any commands using GREP, SED, FIND, AWK, etc. that actually work properly, so use the Windows Method!)

  • This command will locate strings within files;
    • grep -Ril WhatEverStringToSearchFor WhatEverPathToSearch
    • -R = Recursive (IE, search sub-directories)
    • -i = Ignore Case (IE, make the string that is being searched for Case Insensitive)
    • -l = Only list the File Names that contain the searched for strings in the results (That's an L (El), not an I (eye) for the switch)

...but, don't want to just find strings, want to replace them, so;

  • grep -rl 'WhatEverTextPatternToBeReplaced' WhatEverPathNameOfFiles --exclude=*.{dll,exe,png,jpg,webp,bcmap,z,tmp,pdf,zip,pack,idx,swf,ORIGINAL} | xargs sed -i 's/WhatEverTextPatternToBeReplaced/WhatEverNewTextPattern/g'

...and with a frustrating note, in that the above doesn't account for spaces (if there are any, in file names and directory names). Couldn't find a solution as grep simply will not produce any output, even with --null and / or -Z that xargs -0 will pay attention to. Woof!

Speed Note

As for speed, the Command Line is about a hundred times faster than doing it from Windows over a network connection.

Permissions

Set the permissions of all files using the below script;

#!/bin/bash

chown -R apache:apache $1
# To show progress: chown -cR apache:apache $1 OR chown -vR apache:apache $1

find $1 -type d -exec chmod 755 {} \;
find $1 -type f -exec chmod 644 {} \;
# To show progress: find $1 -type d -exec chmod 755 {} \; -print AND find $1 -type f -exec chmod 644 {} \; -print
# The -print may need to go before the ; ( semi-colon )...

If the script file is named CHANGE.sh, then type: ./CHANGE.sh WhatEverPathName

Showing progress isn't recommended as it will lengthen the time considerably.

Watch Out for...

If using WordFence, make sure this file /.user.ini has the proper Domain Name