How to copy / move WordPress sites from one place to another

I am new to WordPress and very impressed with the platform ... This is until it is time to publish my local Wordpress MAMP site on my production server. There is simply no clear and easy way to transfer a site from one server to another.

Goal:

Move your complete Wordpress site from one place to another while retaining all media, settings, and content.

Existing method limitations:

  • Built-in export / import function
    • Does not transfer themes or settings
    • Adds to current content, but does not replace current articles or delete old ones.
  • Performing export and import sql-dump
    • paths are absolute and not updated, so links, etc. all are broken on the new site.

Note:

The code offers this multi-step solution , but I'm looking for something simpler. This is not practical for retransmissions, as in the publishing scenario.

+4
source share
6 answers

You can’t do it like this (as far as I know)

  • You move files
  • Moving a database using export / import in phpMyAdmin
  • Change the configuration (in / wp-config.php) to display the new database settings.
  • run the following sql queries in phpMyAdmin:

Update site settings:

UPDATE wp_options SET option_value = replace(option_value, 'http://oldsite.com/path', 'http://spankingnew.com/otherpath') WHERE option_name = 'home' OR option_name = 'siteurl'; 

Updating message content and messages / URLs at the same time:

 UPDATE wp_posts SET post_content = replace(post_content, 'http://oldsite.com/path', 'http://spankingnew.com/otherpath'), guid = replace(guid, 'http://oldsite.com/path', 'http://spankingnew.com/otherpath'); 

And you need to do it.

Of course, other problems may arise along the way, but I have done so several times.

@ Yarin noted that there is a much simpler way to update site URLs : just bind the URL settings in / wp -config.php.

In / wp-config.php add this:

 define('WP_HOME','http://{my site path}'); define('WP_SITEURL','http://{my site path}'); 

This set-and-forget option will automatically update all the URLs in the database no matter what data you import. This is especially useful if you are constantly importing data from another site, for example, into an out-of-production publishing scenario.

+4
source

A simpler method I found is to open a MySQL dump in something like notepad ++

Then search and replace, for example http://www.oldsite.com , with http://www.newsite.com

then import the dump using php myadmin

Amendment

One of the main problems when moving a wordpress site from one domain to another is mainly related to any plugins or themes that store settings in the database.

The usual search and replace methods do not work, because some themes or plugins store data in a serialized format.

let's say in your theme plugin you have a setting called site home: site: http://oldsite.com '

Serialized it will be stored in the database as follows:

 {s:9:"site-home";s:18:"http://oldsite.com";}` 

Note s:** serialized array stores the string and the number of characters in the string

therefore, if you perform a standard search and replace as previously described

 replacing http://oldsite.com to http://mynewsite.com 

20 characters left now, not 18

However, the standard search and replace, as described above, will only update the matched string, the number of characters will not be updated.

serialized data will be changed to {s:9:"url";s:18:"http://mynewsite.com";}

This is what Wordpress interrupts because the data in the serialized array is now corrupted, as the number of characters is no longer correct.

The best tool, in my opinion, for migrating Wordpress sites is made by some guys at interconnect / it.

It checks serialized arrays and updates the number of characters as well as standard strings.

If you are migrating a wordpress site, this is the only tool you should use. and his free

search and replace Wordpress database

+2
source

Perhaps the cleanest solution I've found so far: http://wordpress.org/extend/plugins/duplicator/

+1
source

arnorhs is correct. There are a few more things that I came across:

  • Some hosts (for example, MediaTemple DV) will not allow a public user to write files, so if this is the case (first make sure that this is a problem), you will want to go to / wp-content / uploads / and make sure it's chmod 777 (or not less 767). All subdirectories must be the same.

  • Sometimes I was not able to import large files into mysql. The shortcut is to open the exported sql file in a text editor and copy several thousand lines to the clipboard and paste them into phpMyAdmin as an SQL query. It works like a charm. Just make sure you finish your copy at the end of the SQL statement.

0
source

This answer is based on arnorhs's above, which is correct - I just want to specify a much simpler way to update the site URLs : Just bind the URL settings in / wp -config.php.

In / wp-config.php add this:

 define('WP_HOME','http://{my site path}'); define('WP_SITEURL','http://{my site path}'); 

This set-and-forget option will automatically update all the URLs in the database no matter what data you import. This is especially useful if you are constantly importing data from another site, for example, into an out-of-production publishing scenario.

( NOTE: If you ever get a server error with this, you may need to enable / disable permalinks in the admin panel to get the URL path changes for registration)

For more on this, see: Wordpress codex: Changing the Site URL


Some other notes ...

If you are trying to move / replace the contents of sites to another existing site, you should:

  • You only need to copy the contents of the themes, plugins, downloads and includes / languages. (Correct me if I am wrong)
  • I would like to delete existing MyQSL data before importing: select all the tables and select "empty" in PhpMyAdmin.
0
source

Yes, one of the most disgusting undocumented WordPress errors :(

I wrote a plugin that correctly solves the whole problem - http://wordpress.org/extend/plugins/root-relative-urls/

This basically converts all the links in your WordPress installation as relative to the roots (that is, start with "/", which are actually equivalent to absolute URLs.) And it will strip the domain from links to images and other assets as they are added to TinyMCE editor, so when creating new content it will be wise to modify these links.

With this plugin, you can access the development site through the IP address, localhost, or any alias that you want to provide to it. And when you dump the database or use only the import / export utility, your content will work just as you would expect in the production process.

This does not work if your development environment has a different root level structure from your production environment, but you can use the htaccess rewrite rules to process this edge - all the same, without having to perform a dangerous search and replace string operations on exported sql.

It also does not work with subdomain multi-user installations, but this is an even larger worm size.

0
source

Source: https://habr.com/ru/post/1338349/


All Articles