WordPress Copy a Website: Difference between revisions

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


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


Line 21: Line 21:


==Modify Domain Name in Files (Don't do this until all the database replacements have been done)==
==Modify Domain Name in Files (Don't do this until all the database replacements have been done)==
The only Directory that should need to be searched is the /wp-content Directory (the wp-admin and wp-includes Directories shouldn't have anything that needs modifying)
First run this command to see what needs changing, before actually changing it;
* grep -Ri WhatEverStringToSearchFor WhatEverPathToSearch
** -R = Recursive (IE, search sub-directories) (same as -r (lowercase))
**-i = Ignore Case (IE, make the string that is being searched for Case Insensitive)
**-l = NOT used in the above example, but noted here as useful, only list the File Names that contain the searched for strings in the results, not the actual text in the file (That's an L (El), not an I (eye) for the switch)
** no need for an * ( asterisk ) at the end of the path as -R implies *
Review the file and think of it as an opportunity to do some house cleaning
* Any log files?  Those can go.
* Any absolute paths (https://WhateverDomainName/Path)?  Think about changing them to relative paths (/Path) instead.
* Some plugins will use their /plugins/WhatEverPluginName to store data.  Hmmm, why not the database like other plugins?  Consider ditching plugins like this and searching for better alternatives.
* etc.


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


*<s>This command will locate strings within files;</s>
*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'
**<s>grep -Ril WhatEverStringToSearchFor WhatEverPathToSearch</s>
 
**<s>-R = Recursive (IE, search sub-directories)</s>
That's an L (El), not an I (eye) for the switch: grep -Rl<--
**<s>-i = Ignore Case (IE, make the string that is being searched for Case Insensitive)</s>
**<s>-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)</s>


<s>...but, don't want to just find strings, want to replace them, so;</s>
In researching this, there were several mentions of "Rust Tools" which seemed to be newer commands that might be integrated into the standard Linux architecture that do the same thing in a comprehensible syntax instead of the above mess (IE, COMMAND "TextToSearchFor" "TextToReplaceItWith" PATH, done!)


*<s>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'</s>
And on frustrating note, in that the above command 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!


<s>...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!</s>
<br />


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


== Permissions ==
==Permissions==
Set the permissions of all files using the below script;<syntaxhighlight lang="text">
Set the permissions of all files using the below script;<syntaxhighlight lang="text">
#!/bin/bash
#!/bin/bash
Line 66: Line 80:
Showing progress isn't recommended as it will lengthen the time considerably.
Showing progress isn't recommended as it will lengthen the time considerably.


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