简体   繁体   中英

How can I safely port my wordpress blog to localhost?

I'm trying to make local development copies for my wordpress blog. I tried first to install wordpress locally (on XAMPP for Windows), install the plugins then import the live data (from a DB backup). The problem is whenever I import the live data I start getting all sorts of errors, even after I change the blog's URL through the database.

Also, the redirection rules I have on my server don't seem to work locally (whether set by wordpress or some of its plugins).

So is there a safe way to just grab the whole thing and make it work locally exactly like the server?

Your help is much appreciated :)

  1. get a full backup of all the files in your online wordpress installation
  2. get a complete backup of the database in use
  3. with any text editing software, process the SQL file of the database backup and change every occurrence of http://old.site with http://localhost
  4. extract the files to your document root
  5. edit wp-config.php to tweak database host/user/pass
  6. import the modified SQL backup
  7. login into admin panel, go to Options->Permalink and save to update permalinks

No need to install anything, just grab what you have online. On windows you might have to rename .htaccess

Maybe somebody will come up with a tool, tutorial or a full HOWTO on this, but in the meantime a few general things on migration:

  1. The redirection rules probably don't work because Windows has trouble with the .htaccess file name due to the starting . . What I usually do is, add (or change) the AccessFileName directive in my Apache config to htaccess.txt that makes the file better usable on Windows. If that doesn't help, put the contents of .htaccess up here.

  2. From my (albeit limited) Experience with Wordpress, it is better to make a raw copy of the Wordpress file and data structure, rather than installing a fresh version and adding all the plugins. There is so much change in the Wordpress code base (automatic update of plugins etc.) that problems are legion. You would then have to change the paths locally in the configuration files, or set up a local path structure that exactly imitates that on the server.

Can you post some of the errors you get when using the live data?

Perhaps a much simpler way would just be to add a host reference from the address of blog to local host eg http://en.wikipedia.org/wiki/Hosts_file . This would allow you to test your blog as if it were actually running on the domain without any of the potential pitfalls.

Here is my 2cents tip:

If you are using plugins, and one of them has an api-key (for an example, Google's analytical toolkit, requires a key), the key may be bound to the IP address where your wordpress blog is located and may fail under the localhost (127.0.0.1). So double check to see if you can obtain a global key which can work on any IP address. This is dependent on the service and plugin. Google Maps is one, Recaptcha is another that comes to mind.

Hope this helps, Best regards, Tom.

kemp's answer is just about perfect. I only wanted to add that you could download something like VirtualBox or VMware and install Linux to it and get a webserver up and running on the virtual machine. This would let you get past any WAMP-LAMP inconsistencies.

Kemp's answer is good - but you don't need to edit your SQL dump, or change the database.

Instead, add 2 lines to your wp-config.php file (I normally add them just above the comment line in the file:

define('WP_HOME','http://localhost');
define('WP_SITEURL','http://localhost');


/* That's all, stop editing! Happy blogging. */ <-- this line already present in the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM