WordPress Clone an Instance: Difference between revisions

From WikiMLT
mNo edit summary
Line 51: Line 51:
</syntaxhighlight>'''12.''' Use <code>grep</code>, <code>sed</code>, <code>xargs</code> to do the same replaces within the new instance document root - if this is necessary, i.e.: some extensions writes their in their cache hardheaded URLs, etc.
</syntaxhighlight>'''12.''' Use <code>grep</code>, <code>sed</code>, <code>xargs</code> to do the same replaces within the new instance document root - if this is necessary, i.e.: some extensions writes their in their cache hardheaded URLs, etc.


'''13.''' Login to the new WordPress instance and inspect weather everything is correct. If you do not have an account you can create on via WP-CLI: <code>sudo -u www-data wp user create newUser example@email.com --role=administrator</code>
'''13.''' Login to the new WordPress instance and inspect weather everything is correct. If you do not have an account you can create on via WP-CLI: <code class="noTypo">sudo -u www-data wp user create newUser example@email.com --role=administrator</code>


== References ==
== References ==

Revision as of 09:27, 9 September 2022

By Us­ing a Plu­g­in

Figure 1. Du­pli­ca­tor – Word­Press Mi­gra­tion Plu­g­in – Snap Creek.

An easy and ro­bust way to Clone an Word­Press In­stance is to use the Word­Press mi­gra­tion plu­g­in Du­pli­ca­tor , pro­vid­ed by Snap Creek. There are few easy steps you need to do.

  1. In­stall the plu­g­in at the source Word­Press site.
  2. Go to the ad­min menu item "Du­pli­ca­tor" and pass through the three easy steps process in or­der to "Cre­ate new Pack­age".
  3. Down­load the new­ly cre­at­ed <package>.zip and the installer.php file.
  4. Set­up a new Vir­tu­al Host and new a Data­base for the des­ti­na­tion site.
  5. Place <package>.zip and installer.php in­to the Doc­u­men­t­Root di­rec­to­ry of the new Vir­tu­al Host.
  6. Ac­cess https://​destination​.example​.com/​i​n​s​t​a​l​l​e​r.php via the web brows­er and fol­low the pro­vid­ed steps.

Op­tion­al­ly, if you need to clone the site at the same serv­er, yo do not need to down­load the <package>.zip file, it is lo­cat­ed in­to the di­rec­to­ry wp-con­tent/back­ups-dup-lite/.

One you fin­ish you must cleanup the source and the des­ti­na­tion site di­rec­to­ries. One way is by us­ing the com­mand line:

# remove 'ech' in order to do the actual changes
sudo find /var/www -type f -name '<package>.*' -exec echo rm {} \;

Fur­ther, for these who don't have the pro ver­sion, they can chance the data­base pre­fix of the new in­stance by the help of the plu­g­in Brozzme DB Pre­fix & Tools Ad­dons (test­ed on WP 5.7.2).

Via the Com­mand-line

Pre­pare a back­up

1. Cre­ate an archive of the doc­u­ment root of the in­stance.

2. Ex­port the ex­ist­ing data­base – by WP-CLI: wp db ex­port. This com­mand will ex­port the data­base in SQL for­mat.

Pre­pare a New Vir­tu­al Host

3. Pre­pare a new vir­tu­al host with­in the web server's con­fig­u­ra­tion at the des­ti­na­tion in­stance.

De­ploy the back­up

4. Move the archive to the des­ti­na­tion in­stance and ex­tract it to the new doc­u­ment root.

5. Pre­pare new emp­ty MySQL da­ta base and im­port the SQL file. Cre­ate al­so data­base user and grant it all priv­i­leges to the new data­base.

6. Im­port the da­ta base in MySQL.

7. Ed­it wp-config.php with­in the new doc­u­ment root, change the data­base name, data­base user and its pass­word – it its nec­es­sary.

8. Ed­it functions.php of the ac­tive theme and add the fol­low­ing lines at the be­gin­ning of the file.

<?php
update_option( 'siteurl', 'https://new-fqdn.example.com' );
update_option( 'home', 'https://new-fqdn.example.com' );

9. Ac­cess the new in­stance via the web in­ter­face. Thus the above PHP func­tions will be ac­ti­vat­ed and will up­date the site URL with­in the data­base.

10. Re­move the lines added at the be­gin­ning of the functions.php file.

11. Use WP-CLI to do ad­di­tion­al re­places with­in the data­base – ref­er­ence.

wp search-replace 'old-fqdn.example.com' 'new-fqdn.example.com' --dry-run

12. Use grep, sed, xargs to do the same re­places with­in the new in­stance doc­u­ment root – if this is nec­es­sary, i.e.: some ex­ten­sions writes their in their cache hard­head­ed URLs, etc.

13. Lo­gin to the new Word­Press in­stance and in­spect weath­er every­thing is cor­rect. If you do not have an ac­count you can cre­ate on via WP-CLI: sudo -u www-data wp user create newUser example@email.com --role=administrator

Ref­er­ences