Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Erick Bongo
Erick Bongo
8,539 Points

Moving WordPress site from server to local host

Hi,

Awhile ago, before I was aware that you could create a local WordPress development area, I created a website which is live. I'd like to transfer it in it's present state over onto a local server so that I can make further changes, without affecting the live website.

So far I've created a backup of all files and the database, placed a copy of these into the root directory, created a new local database updated the wp_config.php to match my local database. updated the site & home url in wp_option to localhost

I can successfully get to the home page but non of the other pages or url's work, they either redirect me to the live website or post a 404. I also cant login.

Does anyone know how I can fix this, so that the url's work ? Zac Gordon maybe you could help?

Thank you

Davie

6 Answers

Hi!

Zac goes over this in this video. Listen for "Search and replace" around 9:00 minutes. He uses a plugin which is easy.

http://teamtreehouse.com/library/how-to-build-a-wordpress-theme/launching-a-wordpress-site/how-to-migrate-a-local-wordpress-site-to-live-server-2

Check out the options table via your local Phpmyadmin. Once you browse this table, it should be clear that the 'siteurl' in the first row will be your live website url.

There are two or three rows that will contain your live website url. I believe you can edit the data inline if you feel confident about that but you didn't hear it from me !

Chris Dziewa
Chris Dziewa
17,781 Points

Did you place your files in a sub-folder within your httpdocs folder? Also, assuming you can log in to your admin panel go to settings > permalinks and click update permalinks. Here is a Wordpress Migration Tutorial you can check out.

Chris Dziewa
Chris Dziewa
17,781 Points

Install a search and replace plugin. You need to find instances of your live sites domain name and change them to localhost. If you have the files within another folder in your root directory it would be replaced with localhost/foldername. This is the same thing you would do in reverse order to make the site live again.

If i recall right, first off try going into your database and edit the _options table. From there you want to update the siteurl entry with your local path and that should allow you to log in.

Once inside your dashboard go to plugins > add new > and search for the plugin "Search and Replace". Install it and activate it. You want to use this plugin to search for strings in your database with "www.yourdomain.com/"" and replace it with your localhost path. This will take care of your img paths and any rogue links that still link back to your live site. Hope this helps.

Erick Bongo
Erick Bongo
8,539 Points

Thank you all,

I changed the url's under wp_config for "siteurl" and "home" but unfortunately am still unable to log in.

lol Zac I actually give the data line a go with this query before but to no avail.

UPDATE wp_options SET option_value = replace(option_value, 'http://yourdomain.tld', 'http://localhost'); 
UPDATE wp_posts SET post_content = replace(post_content, 'http://yourdomain.tld', 'http://localhost'); 
UPDATE wp_posts SET guid = replace(guid, 'http://yourdomain.tld','http://localhost'); 
UPDATE wp_links SET link_url = replace(link_url, 'http://yourdomain.tld', 'http://localhost');

I'll try as you suggest Chirs and use the search replace plugin in reverse, I was considering this method but was unsure if it world work or just cause further problems.

Chris Dziewa
Chris Dziewa
17,781 Points

You really shouldn't have problems with it. Just make sure you replace it with the right file path. The problem you are running into is that the links are relative to your live website so they aren't even looking for local files. Before you search and replace it is a good idea to pull up chrome developer tools just to see what is showing up in the file paths.

Erick Bongo
Erick Bongo
8,539 Points

I inspected the links and It appears I've been successful in changing the url's since there now all pointing to the correct addresses such as "localhost/mysite/contact" but now am receiving an object not found message.

I just ran a search and it seems I may have to create a virtual host, although this in new territory for me.

Erick Bongo
Erick Bongo
8,539 Points

Chris thanks for the tip about the permalinks I've eventually got everything working :) I still wasn't able to login to my wordpress admin panel but I did notice that there are permalink setting within phpmyadmin which was set to "%post%" so I deleted this and thankfully all the pages are now working.

Cheers for your help, much appreciated.

Chris Dziewa
Chris Dziewa
17,781 Points

Glad you got it working Davie! WordPress can often be quite frustrating!

Erick Bongo
Erick Bongo
8,539 Points

haha yep I guess that's the down side to using a cms !