Make single Roundcube instance use multi different databases

I had to configure webmail service with Roundcube which would allow connecting multi mail servers o one platform. Every mail server had it’s own Roundcube instance already, but idea was, that only one installation can handle all mail servers.

I found out, that this can be done pretty symple with some php in roundcube configuration.

Open your roundcube configuration file, for example:

vi /var/www/roundcube/config/

Fetch correct hostname for specific webmail instance in php variable.

$host = $_SERVER['SERVER_NAME'];

Then you should create switch statement that will be able to manage correct database connection and host for specific server name – mail service. You can also have different types of database. For example mysql and postgres.

switch ($host) {
case "":
$config['db_dsnw'] = 'mysql://rcdb1:somepass@';
$config['default_host'] = "";
case "":
$config['db_dsnw'] = 'pgsql://rcdb2:somepass2@';
$config['default_host'] = "ssl://";
case "":
$config['db_dsnw'] = 'mysql://rcdb4:somepass3@';
$config['default_host'] = "ssl://";

Idea is, that when user will type url, this hostname will be saved in $host. Switch statement will then use proper database and hostname for that specific hostname. Also, default_host should be defined so that correct hostname for mail server will be set.

I tried this on webmail instance with 4 different mail servers, with different database types also and it works.


Got Something To Say:

Your email address will not be published.


I accept the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2022
Hosted by SIEL

About author