[wp-hackers] How to sync/mirror 2 WP multisite installs using one database?

Claudio Simeone mrbrog at gmail.com
Thu May 26 07:49:47 UTC 2011


Hi all,

For reasons that don't depends from me, I have to use two separate
servers to run an enterprise WP multisite.
So I have this setup:

server 1: Back-end with a WP with Multisite active (e.g. www.private-wp.com)
server 2: Front-end with a mirrored copy of the WP install on server 1
(e.g. www.public-wp.com)
server 3: mySQL server, running on a separate machine, but accessible
from both server 1 and server 2

the backend install is only used to manage all the content: posts,
pages, sites etc... and is restricted to an editorial team and it is a
private website.
the frontend install is on the public website and it's a read only
version (with wp-admin not used).

Now, since the multisite feature is active, I need in the public
website to have correct urls of blogs created and managed in the
private website.
For example in these tables

wp_options (siteurl, home)
wp_site (domain)
wp_sitemeta (siteurl)
wp_blogs (domain)
and in every wp_N_options table (siteurl, home)

all field values refer to the private-wp URL/domain, for example:

www.private-wp.com/myblog/mypost/

Now, in the public website, this has to be

www.public-wp.com/myblog/mypost/
and so on...

Now, I can use 2 distinct databases (wp_private_db and wp_public_db)
and sync the public one every night through a PHP script that

- drops all tables in wp_public_db
- copies all tables from wp_private_db to wp_public_db
- replaces all urls in all tables in wp_public_db with correct values

I tried this and it seems to work, but I don't like too much this
solution because the DB is large and I fear that dropping/copying a
lot tables can create problems, so I wonder if there's a simpler
solution to my problem, for example using just one DB and replacing
URLS on the fly with something like in wp-config.php

define('WP_SITEURL', 'http://www.public-wp.com');
define('WP_HOME', 'http://www.public-wp.com');

Any ideas on the best way to get this work?

Thank you in advance,
Claudio


More information about the wp-hackers mailing list