WordPress.org

Ready to get started?Download WordPress

Forums

Multiple domains multiple databases one theme (10 posts)

  1. ltcommander
    Member
    Posted 1 year ago #

    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?

  2. govpatel
    Member
    Posted 1 year ago #

    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.

  3. ltcommander
    Member
    Posted 1 year ago #

    Ok, thank you

  4. michael.mariart
    Member
    Posted 1 year ago #

    You can actually do this by uisng a WordPress 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.

  5. ltcommander
    Member
    Posted 1 year ago #

    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.

  6. michael.mariart
    Member
    Posted 1 year ago #

    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.

  7. ltcommander
    Member
    Posted 1 year ago #

    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!

  8. Maraki
    Member
    Posted 1 year ago #

    so does this work?

    Let us know!

  9. ltcommander
    Member
    Posted 1 year ago #

    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.

  10. bcworkz
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags