In many cases you may want to make changes to an existing WordPress website. The only problem is that the website is live, online, and you don’t want to do anything to mess things up “live” or you don’t want to ruin user’s experience by showing them new stuff or errors while they’re browsing the website. So what you can do ?
The answer is simple: you need an identical copy of the website on your machine so you can work risk free. Ok, sounds good but how you can do that ? I’ll answer to this question in few steps that you have to follow in order to have a copy of the website on your localhost.
– On the live website go to cPanel and then find phpMyAdmin.
– On the left hand side select the database you want to export (same database that you’re using in wp-config.php file)
– On the screen that opens select the FORMAT to SQL and click “GO”. You’ll notice in your browser that the download of the file has started. Now in your “Downloads” folder you’ll have the database save in a .sql file.
– I am using FileZilla as my FTP client. You can use any other ftp client that’s not a problem. Once you connected to the website’s server via ftp, copy the whole content of the public_html folder into a folder on your machine. It may take a while depends on how big the website is.
– Once you’ve done that you have to copy that folder in your XAMP/MAMP in a folder called htdocs (on MAMP) or www (on XAMP).
– Now open phpMyAdmin on your local machine. Create a new database and look for the “import” button.
– On the screen that opens, select the file you’ve just exported from the live website and click “GO”
Now you have the database all set up on your local machine. The problem is that in the database you just imported there are links belonging to the live website like http://site-example.com and now you are using something like http://localhost:8888/site-example.com. In order to fix that you have to click on the website’s database on the left-hand side and then look for a tab called “SQL”. In that box you have to run the following SQL commands:
UPDATE wp_options SET option_value = replace(option_value,'http://www.example.com','http://localhost/example') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content,'http://www.example.com','http://localhost/example');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.example.com','http://localhost/test-site');
One more small step and we’re good to go. Now you have to open the wp-config.php file and update the user name, database name and password to match the ones you have on your local machine. That should be it. Now if you go to http://localhost/example you should be able to see an identical copy of http://www.example.comI know there are lots of plugins to migrate but most of them faild when I tried to use them so I stick to the old school method.
How do you migrate wordpress websites ? Do you use a plugin or a manual method as described in this article ? I am curious how you guys are doing it. Looking forward for your thoughts.
For any questions, do not hesitate to leave a comment bellow.
Spread the word:Wednesday 27 February 2019 Marian V. Pop
Get latest blog posts, portfolio updates and more, straight into your inbox.