• Hi.. we have a couple of sites running wordpress that need to be run on multiple URLs.
    Our set up is this. We have a testing tier with the example URL site.testing.foo.com and a production tier using site.foo.com. Both are running the same code base that is a git repo that is moved from the testing to production.

    Furthermore, the testing and production tiers have what we call “authoring” servers that share the same physical document root and database. This authoring box is a straight out of the box fully functional WP install running the sites off of the URLs: site.authoring.testing.foo.com and site.authoring.foo.com.

    The “public” facing servers, site.testing.foo.com and site.foo.com are locked down to bare permissions for both the DB and the filesystem and wp-admin is locked down.

    so.. in short, we need to have the same code base/DB run on multiple URLS on different servers without having to hack the DB everytime.

    Is this even possible? Drupal has no issues doing this out of the box.

Viewing 4 replies - 1 through 4 (of 4 total)
  • As far as I know, no, it is not possible to run different WordPress domains using the same database.

    I have three domains that use the same exact code base, but different DBs.

    dev.fqdn.tld

    staging.fqdn.tld

    prod.fqdn.tld

    To do this, I just took the production database and made two copies, one for dev, one for staging. I then made all the required DB changes. Since the data doesn’t need to be kept up to date on dev/stg, I just refresh it every 6-12 months.

    It’s not the easiest setup, but once done, all you need to do is make sure the wp-config.php file points to the correct DB.

    Moderator Sergey Biryukov

    (@sergeybiryukov)

    WordPress Dev

    Try adding this to your wp-config.php file:

    define('WP_HOME',  "https://{$_SERVER['HTTP_HOST']}");
    define('WP_SITEURL', "https://{$_SERVER['HTTP_HOST']}");
    
    ob_start( 'ob_replace_home_url' );
    function ob_replace_home_url( $content ) {
    	$home_urls = array(
    		'https://site.testing.foo.com',
    		'https://site.foo.com',
    		'https://site.authoring.testing.foo.com',
    		'https://site.authoring.foo.com',
    	);
    
    	$content = str_replace( $home_urls, WP_HOME, $content );
    
    	return $content;
    }

    Most of the time, just WP_HOME and WP_SITEURL would be enough to run the same install from multiple domains. The output buffering here just makes sure that URLs in content (images, etc.) always have the currently requested domain.

    Thread Starter charriman

    (@charriman)

    we are doing that between the “testing” and “prod”.. copying the DB back to testing and hacking the DB so that the URLs are correct.

    As far as the “authoring” part, the “authoring” server and the “public” server are sharing the same filesystem via NFS and DB using different mysql accounts. The internal DNS points site.foo.com to the “authoring” box and externally that URL is pointed to the “public” box.

    The BIG problem is that now on the testing side when you log in to site.testing.foo.com/wp-admin, it forwards to site.authoring.testing.senate.gov/wp-login and bombs out. I can’t figure out what the hell is going on.
    I just don’t understand why WP isn’t agnostic to that stuff so that everything could be relatively pathed.

    Thread Starter charriman

    (@charriman)

    Sergey,
    How does that affect what is in the DB as far as the URLs are concerned? Does it replace what’s in the DB with the content of the Variable?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple URLs with same code base.’ is closed to new replies.