WordPress - moving from one host to another

2019-01-20 06:37发布

问题:

I am trying to move a WordPress installation from one server to another one, including all of the SQL data, and the file-system data (photos,template files).

I just have a problem changing the URLs in the database, since I need to replace the new URL with the old one.

I would love to have some suggestions about how can I replace the URLs (maybe there's a rplace statement in SQL?)

Thanks in advance.

回答1:

Edit 5/16/2015

It's much better to use interconnectit.com WordPress Serialized PHP Search Replace Tool to find/replace URLs in the database and to correctly deserialize/reserialize that data. Doing a find/replace in a text dump or with the UPDATE queries below will break serialized data.


Several easy ways: How to Move WordPress Blog to New Domain or Location » My Digital Life:

UPDATE wp_options SET option_value = replace(option_value, 
'http://www.old-domain.com', 'http://www.new-domain.com')
 WHERE option_name = 'home' OR option_name = 'siteurl';

and others: How to Find and Replace Text in WordPress MySQL Database using SQL When Changing Domains » My Digital Life

Search RegEx « WordPress Plugins for grepping through posts and pages as a WP plugin-based way to replace image and other URLs in posts and pages.

And there's Moving WordPress « WordPress Codex.



回答2:

One thing to be aware of is that WordPress stores some of it's data using serialised arrays (some plugins in particular, such as cforms, do this).

In instances where the site URL data may be serialised, simply updating the site URL text can change the length of data in the serialised string, corrupting the data and breaking things.

Interconnectit have a php script that takes serialisation into account when doing a search replace in the WordPress database. Github repo of the script here.

I have used this script in numerous WordPress migrations and it has been a lifesaver for me.



回答3:

You could simply dump the mySQL in a flat file and open it up in your favorite editor. Than do a find and replace for fully qualified domain name if you are literally change domains. That should take care of WordPress specific URL settings as well, so all your links in pages, posts, sidebars etc. will work. Also be sure to change the local path's recorded in the DB to reflect what the new ones will be as well.

Once your done import the mySQL file in to the new DB and have at it. If something when wrong in transit than you'll definitely know. :)



回答4:

There is indeed a REPLACE() function in MySQL, but I would recommend doing what hsatterwhite suggests and editing the whole MySQL dump as a flat file before re-importing, not least because the REPLACE() function is case sensitive.



回答5:

1) in your current server, go to phpMyAdmin and export your database

2) open the exported file in your fav code editor, find and replace in the whole document your ex base url (http://www.exdomain.com) with your new one (http://www.newdomain.com)

3) go to the new server, import the SQL file with phpMyAdmin

4) change DB user/pass/host in your wp-config.php

5) transfer via ftp all the files from the old server to the new one

and you should be done.

If you also change the directory path: delete your .htaccess and let Wordpress generate a new one updating the permalink options in the back-end.

This has always worked for me, I use to do this when it's time to move a localhost installation to the final production server.

Hope it helps.



回答6:

This is a really straight forwarded procedure with no frills but extremely detailed for newbies

  • Make a full wordpress backup from your local server/host using cpanel. (wp + db)
  • download the backup1.tar.gz generated
  • Install a new wp site (default theme) on the target host. Same release, please!
  • warning: If they are different, leverage both releases.
  • Make a full wordpress backup from your target host using cPanel. (wp + db)
  • download the backup2.tar.gz generated
  • Additionally backup (export) wp-admin and wp-users target mysql backups; save them for future use ahead.
  • enter target host cPanel > file Manager > enter wp diretory > clear all files
  • upload local host wp backup1.tar.gz files to target host wp directory > extract files
  • copy wp-config.php file from backup2.tar.gz file
  • paste overriding wp-config.php file on target host wp directory
  • enter target host > cpanel > phpmyAdmin > find mySQL BD name of your target wp host and drop all tables.
  • restore (import) local wp using backup1.tar.gz softsql.sql file to mySQL db on target host
  • drop wp-admin and wp-users tables after restore. Restore (import) wp-admin and wp-users you saved before. This will guarantee target wp authentication when entering target host wp administrative tasks.
  • test target host wp url
  • The wp-config.php copy/paste is to restore target host wp and mySQL original authentications.
  • Test target wp at /wp-admin mode.
  • that's it! Enjoy.


回答7:

I think the guy is talking about hard links in his page/ post content. You need to apply @markratledge MySQL replace function link this...

UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

This will replace all the links in you post/ page content...



标签: wordpress