• 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)

    (@sterndata)

    Volunteer Forum Moderator

    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.

    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

    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)

    (@sterndata)

    Volunteer Forum Moderator

    @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.

    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?

    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.