Title: Replicate wordpress on offline staging server
Last modified: June 21, 2019

---

# Replicate wordpress on offline staging server

 *  [oguruma](https://wordpress.org/support/users/oguruma/)
 * (@oguruma)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/replicate-wordpress-on-offline-staging-server/)
 * I have a functioning wordpress site on a live server. I want to replicate that
   in a virtualbox so I can closely replicate the production environment on my desktop.
 * I set up the virtualbox and I moved the files and imported the database.
    I am
   using PfSense DNS Resolver so my staging server is staging.com. The website is
   mysite.staging.com. I have changed the site url on the options table to mysite.
   staging.com
 * The site loads fine with the exception that images don’t load. I’m assuming that’s
   because they have their original url on my live server.
 * So… What’s the best way to go about this?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [6 years, 11 months ago](https://wordpress.org/support/topic/replicate-wordpress-on-offline-staging-server/#post-11658514)
 * Use either the search-replace command of wp-cli or the plugin “better search 
   replace” to search for `http://oldsite.com` and replace with `http://stagingsite.
   com`.
 *  [tsguitar](https://wordpress.org/support/users/tsguitar/)
 * (@tsguitar)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/replicate-wordpress-on-offline-staging-server/#post-11658522)
 * Can you put a filter on any calls to image URLs? So you’d filter out whatever
   part of the URL refers to an online server and replace it with local://mysite.
   staging.com or something similar? Using str_replace might work: [https://www.php.net/manual/en/function.str-replace.php](https://www.php.net/manual/en/function.str-replace.php)
 * So something like:
 *     ```
       $onlineimageurl = "http://xxxyyy.cloudfront.net/images/";
       $localimageurl = "local://mysite.staging.com/images";
       $wordpressimagelocal = str_replace ($onlineimageurl, $localimageurl, $wordpressimageonline);
       ```
   
 * Now $wordpressimageonline spits out a URL with the first part of it replaced 
   to point to your local copy. I think?
 * Or you could do a find a replace in your local database using this same logic:
   find the online beginning URL of all images and replace that URL with your local
   URL. WordPress has some find and replace plugins, though if you can manage this
   on your local database that might be easier. That would change all image URLs
   in the database to point to a local copy instead of the online one.
 * Keep us posted!
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [6 years, 11 months ago](https://wordpress.org/support/topic/replicate-wordpress-on-offline-staging-server/#post-11658531)
 * [@tsguitar](https://wordpress.org/support/users/tsguitar/) A DB find and replace
   not done with a serialization-aware parser will break the DB. Please do not suggest
   direct SQL search and replaces.
 *  [tsguitar](https://wordpress.org/support/users/tsguitar/)
 * (@tsguitar)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/replicate-wordpress-on-offline-staging-server/#post-11658576)
 * Oh yikes! I’ve done that kind of find and replace in the past without any trouble.
   In fact, it was nearly this exact kind of situation where I needed to find old
   URLs and replace them with new ones.
 * So maybe replacing the URL through a filter after it’s called out of the DB is
   better?
 *  [autotutorial](https://wordpress.org/support/users/autotutorial/)
 * (@autotutorial)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/replicate-wordpress-on-offline-staging-server/#post-11658650)
 * [https://codex.wordpress.org/Function_Reference/maybe_serialize](https://codex.wordpress.org/Function_Reference/maybe_serialize)
   
   In some cases WordPress can serialize the data, as it also matters how long byte
   it creates problems with a raw search and replacement. Example s:20 indicates
   a string 20 bytes long, what happens if I change an old path to the new one but
   that is different from 20 bytes? Simply the database breaks. The code statement
   should not be used without knowing what to do, use plugins that deal with the
   serialization of objects.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Replicate wordpress on offline staging server’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 4 participants
 * Last reply from: [autotutorial](https://wordpress.org/support/users/autotutorial/)
 * Last activity: [6 years, 11 months ago](https://wordpress.org/support/topic/replicate-wordpress-on-offline-staging-server/#post-11658650)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
