How Do I Migrate A WordPress Website From One Domain To The Other?

Here is a challenge for you. You have developed a customer website locally or in a domain ‘dev’ ​​& now desire to move to the manufacture domain. Obviously, you will copy the directory of WordPress, all plugins & themes and files and then you will as well transfer the database.

However your database is complete of references to the development website. When you attempt to run it, all kinds of things will break. You first notice troubles only WordPress insists that redirect the domain of development. Then, once you have solved it, you will understand the troubles that actually disagreeable when things work approximately, however not quite right.

Let’s go through these matters one by one & understand what requirements update and how to do it.

1)      Telling WordPress that the site’s location has changed

WordPress stores the website location in the options table. You can observe it when you go to Settings->General.



If the LINK there is not the URL of the production website, WordPress will always redirect you to the development URL. It data comes from the options table, however I discover that the easiest, simple and safest way to ‘fix’ it is by entering the accurate URL in the wp-config.php file.

define(‘WP_HOME’, ‘’);

define(‘WP_SITEURL’, ‘’);

These 2 reports tell WordPress to disregard the values in the DB & utilize the home & website-URL values that you state in the PHP. It is particularly suitable if you regularly move from production to development. By forcing it in the PHP, you keep away from the need to continually edit the database.

2)      Updating URLs in posts and custom fields

Most of the migration duty is to update all the posts & custom fields to the URL of the website of production. If you keep in mind, when a link or an image is inserted, WordPress will store it with full path. That is great when you are developing the website, however all these absolute references that update when you are moving to the new website. Otherwise, all lines & images online still go to the development server.

It will be a vicious difficulty, since at first sight; things come into view to work. Only later find out that you are really linking to the wrong places & upload images from a website could be online at any time.

Warning: We are going to bulk-edit the database next. Don’t do this previous to you have made backup of the entire database.

Utilize a database editing tool such as PHPMyAdmin. Navigate to the database right database, if you have numerous. You can back up the database utilizing PHPMyAdmin, using the ‘export’ tool.

These MySQL declarations will replace URLs from development to production. Clearly, you require replacing the sample URLs with your real ones. As well, when you copy/paste from here, be certain that quotes are all usual, single-quote characters. In English keyboards, they are situated next to the ENTER key, jointly with the double-quote chars. The quotes that you copy from this page will most likely be the incorrect character.

  • UPDATE wp_options SET option_value = REPLACE(option_value, ‘http://devdomain.local‘, ‘‘) WHERE option_value NOT LIKE ‘%{%’;
  • UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, ‘http://devdomain.local‘, ‘‘) WHERE meta_value NOT LIKE ‘%{%’;

Hint: After you run each of these queries, PHPMyAdmin will inform you how lots of entries were updated. Check that this number makes sense.


3)      Updating file paths from development to production websites

We are approximately there. The last thing is to alter file directories. Many times, when you upload pictures, audio or video, WordPress will save the complete path of these items in the database – usually in custom field values. You require replacing them.

UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, ‘/home/dev/wordpress ‘, ‘/home/prod/wordpress ‘) WHERE meta_value NOT LIKE ‘%{%’;

Again, we are making sure that just ‘regular’ entries are replaced & not serialized data.


4)      So, what about serialized arrays?

There is no way to update serialized arrays utilizing just MySQL queries. You require utilizing PHP, loading the arrays, searching the values, replacing them & serializing back.

This is why we give confidence developers to keep away from using serialized arrays to hold user-data. Types don’t utilize serialized arrays for any data that might require updating when websites move. For repeating fields, we utilize multiple keys in its place of one key with serialized data.

Leave a Reply

Your email address will not be published. Required fields are marked *