{"id":9,"date":"2018-03-24T09:52:00","date_gmt":"2018-03-24T09:52:00","guid":{"rendered":""},"modified":"2021-02-22T01:14:04","modified_gmt":"2021-02-22T01:14:04","slug":"clone-or-migrate-wordpress-to-different-domain-name-fix-static-links","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2018\/03\/clone-or-migrate-wordpress-to-different-domain-name-fix-static-links.html","title":{"rendered":"Clone or Migrate WordPress to a Different Domain Name &#038; Fix Static Links"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2018\/03\/wordpress-logo-250.png\"><img decoding=\"async\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2018\/03\/wordpress-logo-250.png\" border=\"0\" data-original-height=\"250\" data-original-width=\"250\" \/><\/a><\/div>\n<p>Some WordPress themes and plugins write the full URL of a website inside their temporary files or database which makes it hard to change the domain name of a wordpress Installation.<\/p>\n<p>In this tutorial, I&#8217;ll clone WordPress from <span style=\"color: #e69138;\">xyz.com<\/span> to <span style=\"color: magenta;\">abc.com\/wordpress<\/span><\/p>\n<p>This tutorial will cover the following 3 steps:<br \/>\n1- Clone or Migrate WordPress<br \/>\n2- Fix Static Links in files<br \/>\n3- Fix Links and serialized strings in database<\/p>\n<p><a name=\"more\"><\/a><\/p>\n<h2 style=\"text-align: left;\">1- Clone or Migrate WordPress<\/h2>\n<p>There are several ways to do this, you can<br \/>\n<span style=\"color: #38761d;\"><span style=\"color: #6aa84f;\"><b>&#8211; Download all the files and databases and re-upload them to the new server:<\/b><\/span><\/span><br \/>\nJust download the files from cPanel or FTP and the database from PhpMyAdmin and re-upload to new server<\/p>\n<p><span style=\"color: #38761d;\"><span style=\"color: #6aa84f;\"><b>&#8211; Or Transfer from a server to another using SSH without downloading\/uploading<\/b><\/span><\/span><br \/>\nOn <span style=\"color: #e69138;\">xyz.com <span style=\"color: black;\">server<\/span><\/span><br \/>\nBrowse to the directory where wordpress is installed and run<\/p>\n<pre>mysqldump -u dbuser -p dbtable &gt; db.sql<\/pre>\n<p>where <i>dbuser<\/i> is the db user name (usually found in wp.config)<br \/>\n<i>dbtable<\/i> is the table name<br \/>\n<i>db.sql<\/i> is a text file containing all your database tables and data<\/p>\n<pre>zip -r wp.zip * .htaccess<\/pre>\n<p>This will zip\/archive all the files, the database files you have extracted and the .htaccess files (which are needed if your webserver is apache, litespeed..)<\/p>\n<p>On\u00a0<span style=\"color: #e69138;\"><span style=\"color: magenta;\">abc.com\/wordpress<\/span> <span style=\"color: black;\">server<\/span><\/span><br \/>\nLogin to your new server\/host using SSH, go to the directory where you want to install wordpress and run the commands<\/p>\n<pre>wget xyz.com\/wp.zip<\/pre>\n<p>This will download the files you have previously zipped\/archived in the previous step<\/p>\n<pre>unzip wp.zip<\/pre>\n<p>to extract all the files and db<\/p>\n<pre>mysql -u dbuser -p dbtable &lt; db.sql<\/pre>\n<p>where <i>dbuser<\/i> is the database user you have created on the new server<br \/>\n<i>dbtable<\/i> is the table name you have created on the new server<br \/>\n<i>db.sql <\/i>is the file you have extracted from wp.zip which was on the old server<\/p>\n<pre>vi wp-config.php<\/pre>\n<p>and modify the database credentials for the new server (user, table, password)<\/p>\n<p>Make sure to delete db.sql and wp.zip from <b>both servers<\/b><\/p>\n<pre>rm db.sql wp.zip<\/pre>\n<p><span style=\"color: #38761d;\"><b>&#8211; Or Copy files if both websites are on the same server and you have SSH access (you need root access if they are on a different domain name)<\/b><\/span><\/p>\n<p>On <span style=\"color: #e69138;\">xyz.com <span style=\"color: black;\">server<\/span><\/span><br \/>\nBrowse to the directory where wordpress is installed and run<\/p>\n<pre>mysqldump -u dbuser -p dbtable &gt; db.sql<\/pre>\n<p>where <i>dbuser<\/i> is the db user name (usually found in wp.config)<br \/>\n<i>dbtable<\/i> is the table name<br \/>\n<i>db.sql<\/i> is a text file containing all your database table<\/p>\n<pre>cp -R * \/home\/yourpath\/yourpath\r\ncp .htaccess \/home\/yourpath\/yourpath<\/pre>\n<p>Where <i>\/home\/yourpath\/yourpath<\/i> is the path of your new installtion\/clone<\/p>\n<p>On\u00a0<span style=\"color: #e69138;\"><span style=\"color: magenta;\">abc.com\/wordpress<\/span> <span style=\"color: black;\">server<\/span><\/span><\/p>\n<pre>mysql -u dbuser -p dbtable &lt; db.sql<\/pre>\n<p>where <i>dbuser<\/i> is the database user<br \/>\n<i>dbtable<\/i> is the new table name<br \/>\n<i>db.sql<\/i> is the database file<\/p>\n<pre>vi wp-config.php<\/pre>\n<p>And modify the database credentials for the new server (user, table, password), you can also do it from FTP<\/p>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">2- Fix Static Links in files<\/h2>\n<p>This will be done from SSH<\/p>\n<p>On\u00a0<span style=\"color: #e69138;\"><span style=\"color: magenta;\">abc.com\/wordpress<\/span> <span style=\"color: black;\">installation, run in SSH<\/span><\/span><br \/>\n<i><span style=\"color: #e69138;\"><span style=\"color: black;\">find<\/span><\/span> -name *.php -exec sed -i\u00a0 &#8220;s;<span style=\"color: #e69138;\">xyz.com<\/span>;<span style=\"color: #e69138;\"><span style=\"color: magenta;\">abc.com\/wordpress<\/span><\/span>;g&#8221; {} ;<\/i><br \/>\n<i><span style=\"color: #e69138;\"><span style=\"color: black;\">find<\/span><\/span> -name *.js -exec sed -i\u00a0 &#8220;s;<span style=\"color: #e69138;\">xyz.com<\/span>;<span style=\"color: #e69138;\"><span style=\"color: magenta;\">abc.com\/wordpress<\/span><\/span>;g&#8221; {} ;<\/i><br \/>\n<i><span style=\"color: #e69138;\"><span style=\"color: black;\">find<\/span><\/span> -name *.css -exec sed -i\u00a0 &#8220;s;<span style=\"color: #e69138;\">xyz.com<\/span>;<span style=\"color: #e69138;\"><span style=\"color: magenta;\">abc.com\/wordpress<\/span><\/span>;g&#8221; {} ; <\/i><\/p>\n<p>Make sure to delete db.sql<\/p>\n<pre>rm db.sql<\/pre>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">3- Fix Links and serialized strings in database<\/h2>\n<p>The easiest way is to do it using a php application called search and replace.<br \/>\nDownload it from<br \/>\n<a href=\"https:\/\/interconnectit.com\/products\/search-and-replace-for-wordpress-databases\/\">https:\/\/interconnectit.com\/products\/search-and-replace-for-wordpress-databases\/<\/a><\/p>\n<p>Extract and upload it to a folder in your wordpress installation, example<br \/>\n<span style=\"color: #e69138;\"><span style=\"color: magenta;\">abc.com\/wordpress\/searchr<\/span><\/span><\/p>\n<p>and open it from your browser, it should detect the database information from wp-config, make sure they are correct<\/p>\n<p>Enter the domain name you want to replace and the new value<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2018\/03\/search-replace.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2018\/03\/search-replace-300x41.png\" width=\"400\" height=\"54\" border=\"0\" data-original-height=\"166\" data-original-width=\"1221\" \/><\/a><\/div>\n<p>You can make a dry run to check which tables will be affected.<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2018\/03\/search-replace-results.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2018\/03\/search-replace-results-300x28.png\" width=\"400\" height=\"36\" border=\"0\" data-original-height=\"117\" data-original-width=\"1270\" \/><\/a><\/div>\n<p>Once you are ready do a live run.<\/p>\n<p>Once live run is done, delete search and replace, you can either delete the directory you uploaded or delete it from its interface.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Some WordPress themes and plugins write the full URL of a website inside their temporary files or database which makes it hard to change the domain name of a wordpress Installation. In this tutorial, I&#8217;ll clone WordPress from xyz.com to abc.com\/wordpress This tutorial will cover the following 3 steps: 1- Clone or Migrate WordPress [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11,6,9,7,8,10],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-commands","category-linux","category-phpmyadmin","category-ssh","category-wordpress","category-zip"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":2,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":390,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/9\/revisions\/390"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}