Title: Multiple domains multiple databases one theme
Last modified: August 20, 2016

---

# Multiple domains multiple databases one theme

 *  [ltcommander](https://wordpress.org/support/users/ltcommander/)
 * (@ltcommander)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/)
 * Hi. I want to install WordPress on three domains. I use Perl to post to WordPress.
   I use wordpress::API::post from cpan.org.
 * This Perl module does not recognize WordPress sites as it assumes the tables 
   to post are standard. I.e only wp_post. So I cannot use sites.
 * What I want to do is to have multiple databases but only one installation of 
   WordPress so that all the sub domains use standard plugins and a theme. I don’t
   want to install the same plugin three times or propagate a tweak in the team 
   to other installations.
 * Is there a way to get WordPress to use different databases based on the domain
   name while keeping the theme and plugins the same?

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [govpatel](https://wordpress.org/support/users/govpatel/)
 * (@govpatel)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/#post-2886692)
 * There no way you can have one wordpress install and separate database of each
   domain name.
 * You will have to have separate install for each domain if you want each to have
   its own databse.
 *  Thread Starter [ltcommander](https://wordpress.org/support/users/ltcommander/)
 * (@ltcommander)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/#post-2886719)
 * Ok, thank you
 *  [michael.mariart](https://wordpress.org/support/users/michaelmariart/)
 * (@michaelmariart)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/#post-2886720)
 * You can actually do this by uisng a [WordPress Network](http://codex.wordpress.org/Create_A_Network)
   installation.
 * Each site won’t have it’s own seperate database, but it will “segment” each sites
   database by using a different prefix for each network site, so you can move/copy/
   whatever the database for one site relatively easily.
 *  Thread Starter [ltcommander](https://wordpress.org/support/users/ltcommander/)
 * (@ltcommander)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/#post-2886722)
 * The catch I have with that is that the Perl Module I use (WordPress::API::Post)
   doesn’t recognize sites. I have to either wait for a new PM or try to write a
   posting function myself.
 *  [michael.mariart](https://wordpress.org/support/users/michaelmariart/)
 * (@michaelmariart)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/#post-2886723)
 * Well, are yo any good with PHP? 😉
 * If you are, there’s a bit of a hacky way of getting around this.
 * In your wp-config.php file you will need to add in something like this:
 * > `if (strpos ($_SERVER [“HTTP_HOST”], “firstwebsite.com”) !== false) {
   >  define(‘
   > DB_NAME’, ‘database1’); define(‘DB_USER’, ‘username1’); define(‘DB_PASSWORD’,‘
   > password1’); define(‘DB_HOST’, ‘localhost’); } elseif (strpos ($_SERVER [“HTTP_HOST”],“
   > secondwebsite.com”) !== false) { define(‘DB_NAME’, ‘database2’); define(‘DB_USER’,‘
   > username2’); define(‘DB_PASSWORD’, ‘password2’); define(‘DB_HOST’, ‘localhost’);}
   > else { define(‘DB_NAME’, ‘database’); define(‘DB_USER’, ‘username’); define(‘
   > DB_PASSWORD’, ‘password’); define(‘DB_HOST’, ‘localhost’); }`
 * Using something like this you can use a different database connection for each
   website that you have pointing to that one account.
 * This means that there’s still a single code-base but all of the content and the
   settings will be separated by using the different databases.
 * One word of warning because I haven’t tested this myself yet. I am not sure how
   teh media gallery will work if you upload two files of the same file name on 
   different sites. It should work (should…) but it’s something that I’d advise 
   you test out for yourself.
 * Hopefully that might help you out a bit.
 *  Thread Starter [ltcommander](https://wordpress.org/support/users/ltcommander/)
 * (@ltcommander)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/#post-2886724)
 * I get this. That’s awesome Michael, thanks!! I am a Perl guy but can do some 
   PHP too! I will give this a go!
 *  [maraki](https://wordpress.org/support/users/neodjandre/)
 * (@neodjandre)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/#post-2886868)
 * so does this work?
 * Let us know!
 *  Thread Starter [ltcommander](https://wordpress.org/support/users/ltcommander/)
 * (@ltcommander)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/#post-2886869)
 * Hi,
 * I can’t remember why but I ended up installing separate installations. I think
   it’s because I use WordPress::API::Post (Perl) to post and that didn’t work with
   such a set up. So, to get it done quickly, I just ended up installing multiple
   WordPress installations.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/#post-2886870)
 * If anyone is thinking of trying Michael’s hack, it appears to me you might also
   want to define WP_SITEURL and WP_HOME to equal HTTP_HOST or an appropriate variation.
   It should work without this, but this would ensure users will not be confused
   by different domains showing up somewhere.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Multiple domains multiple databases one theme’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 9 replies
 * 5 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/multiple-domains-multiple-databases-one-theme/#post-2886870)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
