How to Install and Configure RoundCube Webmail Client with Virtual Users in Postfix – Part 4

In Parts 1 through 3 of this Postfix series we explained, step by step, how to set up and configure an email server with virtual users. We also showed you how to access one of those accounts using Thunderbird as email client.

  1. Setting Up Postfix Mail Server and Dovecot with MariaDB – Part 1
  2. Configure Postfix and Dovecot Virtual Domain Users – Part 2
  3. Install and Integrate ClamAV and SpamAssassin to Postfix Mail Server – Part 3

In this era of connectivity when you are likely to need access to your inbox from anywhere (and not just from your home computer), server-side software known as webmail clients make it possible for you to read and send emails through a web interface.

Install RoundCube Webmail for Postfix on CentOS
Install RoundCube Webmail for Postfix Mail Server – Part 4

Roundcube is one of such programs, and given its many features (which you can read more about in the project’s website) it is the one we have chosen to use in this tutorial.

Install Roundcube Webmail for Postfix

In CentOS 7 and based distributions such as RHEL and Fedora, installing Roundcube is as easy as doing:

# yum update && yum install roundcubemail

Note: Please keep in mind that Roundcube is included in the EPEL repository, which we must have already enabled as outlined in Part 1.

In Debian 8 and its derivatives such as Ubuntu and Mint, you will need to enable the Jessie backports (web) first:

# echo "deb jessie-backports main" >> /etc/apt/sources.list

Then install Roundcube as follows:

# aptitude update && aptitude install roundcube

Regardless of the distribution we’re using, we now need to create a database to store Roundcube’s internal structure.

In Debian 8, the installation process will take care of this:

Choose Yes when prompted whether you want to configure the Roundcube database using dbconfig-common:

Configure Roundcube Webmail Database
Configure Roundcube Webmail Database

Choose mysql as database type:

Select Roundcube Database Type
Select Roundcube Database Type

Provide the password for the MariaDB root user:

Set Roundcube Database Password
Set Roundcube Database Password

And choose a password for roundcube to register with the database server, then click Ok:

Register RoundCube with Database
Register RoundCube with Database

Confirm the password you entered during the previous step:

Confirm Roundcube Database Password
Confirm Roundcube Database Password

And before long, you will have a database named roundcube and its corresponding tables created automatically for you:

MariaDB [(none)]> USE roundcube;
MariaDB [(none)]> SHOW TABLES;
Check Roundcube Database Tables
Check Roundcube Database Tables

In CentOS 7, you will need to create the database manually by either logging on to phpMyAdmin or via the command line. For brevity, we will use the second proposed method here:

# mysql -u root -p
MariaDB [(none)]> CREATE DATABASE RoundCube_db;

Then exit the MariaDB prompt and run the following SQL script:

# mysql -u root -p RoundCube_db < /usr/share/roundcubemail/SQL/mysql.initial.sql

Please note that in Debian you can also perform these steps manually. Thus, you get to rename your database if you want to instead of having it named automatically “roundcube” as seen before.

Configure Roundcube for Postfix

To begin, you should note that from RoundCube v1.0 and onwards, the configuration settings are included in one file only, as opposed to previous versions where they were split between two files.

First, locate the following file and make a copy named in the same directory. Use the -p option to preserve mode, ownership, and original timestamp:

# cp -p /etc/roundcubemail/ /etc/roundcubemail/

Next, make sure Roundcube can access the database we created previously. In db_dsnw, replace user and password with an username and password with permissions to access the RoundCube_db.

For example, you could use the same administrative account you utilized to log on to phpMyAdmin in Part 1, or you can just use root if you want.

$config['db_dsnw'] = 'mysql://user:password@localhost/RoundCube_db';

The following settings refer to the hostname, ports, authentication type, and so on (they are self-explanatory, but you can find more details by reading the comments in the configuration file):
$config['default_host'] = 'ssl://';
$config['default_port'] = 143;
$config['smtp_server'] = 'tls://';
$config['smtp_port'] = 587;
$config['smtp_user'] = '%u';
$config['smtp_pass'] = '%p';
$config['smtp_auth_type'] = 'LOGIN';

These last two settings (product_name and useragent) refer to the header in the web interface and to the email headers sent with the messages.

$config['product_name'] = 'Linuxnewz Webmail - Powered by Roundcube';
$config['useragent'] = 'Linuxnewz Webmail';

In order for Roundcube to use virtual user’s authentication for outgoing mail, we need to activate the virtuser_query plugin (which can be found in /usr/share/roundcubemail/plugins):

$config['plugins'] = array('virtuser_query');
$config['virtuser_query'] = "SELECT Email FROM EmailServer_db.Users_tbl WHERE Email = '%u'";

Note how the SQL query above points to the EmailServer_db database we set up initially in Part 1, which is where the information about the virtual users is stored.

Finally, similarly to what we did in Part 1 to be able to access phpMyAdmin’s web interface using a web browser, let’s dive into the Roundcube / Apache configuration file at:

# vi /etc/httpd/conf.d/roundcubemail.conf # CentOS 7
# nano /etc/roundcube/apache.conf # Debian 8

And place the following lines inside the indicated tags:

Debian 8:

<IfVersion >= 2.3> 
    Require ip AAA.BBB.CCC.DDD 
    Require all granted 

CentOS 7:

<IfModule mod_authz_core.c> 
    # Apache 2.4 
    Require ip AAA.BBB.CCC.DDD 
    Require all granted 

Though not strictly required, it’s a good idea to change the alias of the Roundcube directory in order to protect yourself from bots that target /roundcube as a well-known door to break into your system. Feel free to choose an alias that suits your needs (we will go with webmail here):

Alias /webmail /usr/share/roundcubemail # CentOS 7
Alias /webmail /var/lib/roundcube # Debian 8

Save changes, exit the configuration file and restart Apache:

# systemctl restart httpd # CentOS 7
# systemctl restart apache2 # Debian 8

Now you can open a web browser and point it to and you should see something similar to:

Roundcube Webmail Login
Roundcube Webmail Login

You can now log on with one of the accounts we configured in the previous articles and start sending and receiving emails using Roundcube from anywhere!

Customizing Roundcube Webmail

Fortunately, Roundcube’s interface is fairly intuitive and easy to configure. At this point, you could spend some 15-30 minutes configuring the environment and becoming familiar with it. Go to Settings for more details:

Customizing Roundcube Webmail
Customizing Roundcube Webmail

Please note that the above image shows the emails that we have received in this account ([email protected]).

You can click Compose and start writing an email to an external email address:

Compose Mail in Roundcube Webmail
Compose Mail in Roundcube Webmail

Then hit Send and check the destination to see if it arrived correctly:

Confirm Postfix Mail Delivery
Confirm Postfix Mail Delivery

Congratulations! You have successfully setup Roundcube to send and receive emails!


In this article we have explained how to setup and configure Roundcube as web client. As you explore Roundcube’s interface you will see how easy it is to use, as described in the Webmail help.

However, don’t hesitate to let us know if you have any questions or concerns – just drop us a note using the comment form below. We look forward to hearing from you!

If you read this far, tweet to the author to show them you care. Tweet a thanks
Gabriel Cánepa
Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

30 thoughts on “How to Install and Configure RoundCube Webmail Client with Virtual Users in Postfix – Part 4”

  1. Hi, I can not connect to roundcube in the log I have this message:

    Cound not connect to ssl:// Connexion refused in /usr/share/roundcubemail/program/lib/Roundcube/rcube_imap.php on line 197 (POST /webmail/?_task=login?_task=login&_action=login)

      • Thank you for your reply but I have this error now :

        SMTP Error : Connection failed : Failed to connect socket: connection refused …

        • I believe you’re trying to connect roundcube through imaps instead of imap. The port should be 143. Make sure you have tls enabled and check the Dovecot config the ensure you have imap only enabled to run netstat -ntlp |grep imap to see if 143 is opened and make sure it is open in the firewall.

    • Hi, I can not connect to RoundCube in the log I have this message:

      Could not connect to ssl:// Connexion refused in /usr/share/roundcubemail/program/lib/Roundcube/rcube_imap.php on line 197 (POST /webmail/?_task=login?_task=login&_action=login)

      • We need more information. Is your mail server working connecting with an email client? What error do you get when you try to login using a round cube?

        We can try to help but it connects with an array in the PHP file based on your setup.


Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.