Wordpress migration to local environment

The Context

I've been assigned to update a 3rd party Wordpress theme and the first task was the migration of the production website to my development environment.

The Migration

  1. I've ssh to the production server, zipped the entire website folder and transferred to my local environment along with the dumped database.
  2. I've Deployed it into a vagrant box with the same lamp configuration of the production server.
  3. I've ran the following updates in the database restored in my development environment.

:

UPDATE wp_options SET option_value = replace(option_value,    'http://production.com', 'http://dev.site') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET post_content = replace(post_content, 'http://production.com', 'http://dev.site');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://production.com','http://dev.site');

The Problem

When accessing the website in my development environment I noticed that many of the production shortcodes are broken.

Any ideas?

Upvotes: 2

Views: 188

Answers (2)

Yash Trivedi
Yash Trivedi

Reputation: 41

You can use "All in one migration" plugin for the transfer any site to localhost. You just need to install "ALL in one migration" plugin in the live server and then create the backup and export it then you need to install that plugin to the localhost as well and then import that backup file to the localhost. and save the permalinks from the setting and that's it.

Here is the plugin Link : https://wordpress.org/plugins/all-in-one-wp-migration/

Upvotes: 1

Frits
Frits

Reputation: 7614

Most migration breaks are caused by bad serialised data.

The easiest way to repair these breaks is to Force Recreate the data. This achievable by forcing the plugin to rewrite the serialised data to the MySQL database.

Following these steps will help with most migration errors you may encounter:

  1. Deactivate and Reactivate all of your plugins
  2. Activate a different (preferrably a default / built-in) theme, and then reactivate your current theme.
  3. Head to Settings -> Permalinks and just click save (keep all your settings the same)

For anyone else reading this answer: It's important to note that almost all of this would be impossible if your URL changed and you did not run the SQL fix mentioned in the question

If needed, I've added my own version of it below, you will just have to remember to replace the oldsite-url.com and newsite-url.com with relevant values.

If the database in question uses a custom table prefix (i.e. not wp_), you will need to remember to find -> replace that as well.

Here's the SQL Query:

UPDATE wp_options SET option_value = replace(option_value, 'http://oldsite-url.com', 'http://newsite-url.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = REPLACE (guid, 'http://oldsite-url.com', 'http://newsite-url.com');
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://oldsite-url.com', 'http://newsite-url.com');
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://oldsite-url.com','http://newsite-url.com');

Upvotes: 1

Related Questions