How do I migrate a wordpress subsite from a staging to a live server (on wordpress multisite)?

I work on wordpress sites with a wordpress multisite install. Now I’m switching from developing on the live server, to working with a staging server and then pushing to the live server when everything is done.

Now of course the database would have to be migrated and updated for each environment in some way (probably both ways; pulled to staging for starting and pushed to live for deployment). But also the themes, templates and assets would have to be migrated.

Read More

Since I’m new to this, I don’t know exactly how this is usually done. I’m looking for a safe and practical solution. I’ve looked into using grunt (which I already use for other tasks) with grunt-wordpress-deploy for example, but it doesn’t seem to be doing everything I want to do.

So my question is: how do I do this? How do I safely and easily synchronize a wordpress subsite between my staging and my live server?

Related posts

Leave a Reply

1 comment

    1. Go to network admin and find the ID of site you want to move ( In the examples below – 17 )

    2. Now you would want to transfer the whole wp-content folder -> uploads -> Sites -> site_id ( in this case wp-content folder -> uploads -> Sites -> 17 , of course you need to have wp on new server – see addendum )

    3. In to the original site on the network, check what theme it uses . FTP to the main site wp-content folder -> Themes and download/ transfer the theme it uses . ( or see below addendum )

    4. Do the same for plugins , go to the original site dashboard, see what plugins it uses . Do not forget to also check what plugins are activated NETWORK WIDE and mu-plugins and transfer those too . For compatibility reasons , I always prefer to transfer the ones I used before and not to download from the wp repository . updates can and will be made later . for now , it is better to keep all the versions the same as original .

    5. Export / Import DB ( using PhpMyAdmin for example ) and then rename the tables :

    ( note the last two – those are tables from the MAIN network DB – not site specific )

    Rename table wp_multi17_commentmeta to wp_newsite_commentmeta;
    Rename table wp_multi17_comments to wp_newsite_comments;
    Rename table wp_multi17_links to wp_newsite_links;
    Rename table wp_multi17_options to wp_newsite_options;
    Rename table wp_multi17_postmeta to wp_newsite_postmeta;
    Rename table wp_multi17_posts to wp_newsite_posts;
    Rename table wp_multi17_terms to wp_newsite_terms;
    Rename table wp_multi17_term_relationships to wp_newsite_term_relationships;
    Rename table wp_multi17_term_taxonomy to wp_newsite_term_taxonomy;
    Rename table wp_multiuermeta to wp_newsite_usermeta;
    Rename table wp_multiusers to wp_newsite_users;
    
    1. After that , we execute the normal wp update sql

    like so :

    **
    To update WordPress options with the new blog location, use the following SQL command:
     note that this depends also on your folder structure ( wp in own folder here, not root )
    **/
    
    UPDATE wp_newsite_options SET option_value = replace(option_value, 'www.oldnetwork.com/multi', 'www.newsite.com/newsite') WHERE option_name = 'home' OR option_name = 'siteurl';
    
    /**
    After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as absolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:
    **/
    
    UPDATE wp_newsite_posts SET guid = replace(guid, 'www.oldnetwork.com','www.newsite.com/newsite');
    
    /**
    If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:
    **/
    
    UPDATE wp_newsite_posts SET post_content = replace(post_content, 'www.oldnetwork.com/multi', 'www.newsite.com/newsite');
    

    DONE – After that – Your new site should be fine .

    However – some residues might be there ( due to specific plugins / themes ) , so search/replace for originalname.com or www.originalname.com or sites/17 could also be made ..

    This process, when understood – can easily be adapted ( reversed ) to transfer also the other way around ( from single to multi )

    Addendum

    If you have a LARGE site with a lot of content ( e.g. images ) – FTP might take too long .
    It would be much faster to do that on the server directly, so I am just adding it here .

    • log in to cpanel ( or whatever ), files manager , and tar the whole uploads/site_id (17 – remember ? )
      folder
    • in PUTTY

    ( or other SSH on your new location )

    [] #cd home/account-name/public_html
    
    • then

      wget -m http://www.old-multi-domain-path/wp-content/uploads/sites/site-id.tar

    ( or zip, or rar etc … )

    you will probably get the file at a folder called www.old-multi-domain-path/wp-content/uploads/sites/site_id.tar

    now , move it to root, and delete the folder

    rm -rf www.old-multi-domain-path/

    • now ftp wordpress to the new server ( or if you prefer to just take the newest version – but it is not reccomanded for compatibility issues . better do upgrades later )

    wget http://wordpress.org/latest.tar.gz

    Now go back up to Phase 3.