• Without using any plugins etc., I am trying to replicate a WordPress site, which I will call, for the sake of argument, ‘www.mysite.com’, at a different subdomain, ‘staging.mysite.com’. I am doing this via ssh and I have full root access. I have taken a fairly basic approach. What I have done is to replace all instances of the string ‘www.mysite.com’ in the files in the WordPress directory with ‘staging.mysite.com’. Similarly, I’ve done an export (mysqldump) of the database from the live site, replaced all instances of the string ‘www.mysite.com’ with ‘staging.mysite.com’ throughout the SQL dump and imported it for the staging site.

    So, theoretically, at this point it should be identical to the original site but with the new subdomain in place. But it’s not working properly – I’m getting some empty links instead of links to pages under the new subdomain and I don’t see how this can possibly happen, given what I’ve done. I’ve tried clearing all caches, to no avail. Any suggestions as to what I might have overlooked? (I should add that all values in wp-config.php have been correctly updated for the new site).

    I used the same approach on another site and it worked perfectly, so I’m at a loss to understand how this could possibly not work, as it’s so fundamental and basic.

    • This topic was modified 1 year, 8 months ago by johnny2r.
Viewing 6 replies - 1 through 6 (of 6 total)
  • replaced all instances of the string ‘www.mysite.com’ with ‘staging.mysite.com’

    Dont do this – you may have got lucky but if https://www.mysite.com is not EXACTLY the same length as staging.mysite.com then you wil break things

    The best way to update the databse data with root / SSH access is to use WP CLI and use WP Search-Replace

    wp search-replace –all-tables –precise “https://old” “https://new”

    wp search-replace –all-tables –precise “https://old” “https://new”

    Thread Starter johnny2r

    (@johnny2r)

    What do you mean by ‘exactly the same length’? What length are you talking about? My understanding is that using wp search-replace –all-tables –precise as you say will have exactly the same effect as doing it directly on the mysqldump file. Is this not the case? I’ll give it a go nonetheless.

    Exactly the same length strings.

    So technically WP stores array data using PHP serialized data formats which basically is a character count followed by the string. see https://en.wikipedia.org/wiki/PHP_serialization_format

    Take the object stored as

    O:8:"stdClass":2:{s:4:"John";d:3.14;s:4:"Jane";d:2.718;}

    and the replace John with Jenny ( different lengths )

    O:8:"stdClass":2:{s:4:"Jenny";d:3.14;s:4:"Jane";d:2.718;}

    You can see that s:4 is wrong ( it should be s:5 ) so now Jenny would actually only be Jenn – now you should have a full understanding why a text replace of a string of different lengths will break WP

    • This reply was modified 1 year, 8 months ago by Alan Fuller.
    Thread Starter johnny2r

    (@johnny2r)

    OK, thanks, that’s clearer. I don’t think I’m doing it quite right, though. I used this:

    wp search-replace –all-tables –precise --allow-root "https://www” "https://staging”

    and got a message saying Couldn’t find any tables matching: https://www” https://staging. So could you perhaps help me by giving an exact command to replace all instances of https://www.mysite.com with staging.mysite.com? I assume this applies only to the database?

    LATER: It’s OK, thanks, I’ve done it: wp search-replace 'www.mysite.com' 'staging.mysite.com' --precise --recurse-objects --all-tables --allow-root

    • This reply was modified 1 year, 8 months ago by johnny2r.
    Thread Starter johnny2r

    (@johnny2r)

    Thanks, figured it out (I edited my post).

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Problems replicating WordPress site’ is closed to new replies.