Install Roundcube Webmail on CentOS 8/RHEL 8 with Apache/Nginx

Roundcube is a free and open source webmail client written in PHP. A webmail is a mail client in your browser, which means instead of reading and sending emails from a desktop mail client like Mozilla Thunderbird, you can access your email from a web browser. Roundcube functionality includes MIME support, address book, folder management, message searching and spell checking. This tutorial is going to show you how to install Roundcube webmail on CentOS 8/RHEL 8 with Apache or Nginx web server.

Roundcube 1.4.2 Release

Roundcube 1.4.2 was released on January 2, 2020. This release features:

  • A responsive skin called Elastic with full mobile device support
  • Email Resent (Bounce) feature
  • Improved Mailvelope integration
  • Support for Redis and Memcached cache
  • Support for SMTPUTF8 and GSSAPI
  • Plus numerous improvements and bug fixes


To follow this tutorial, it’s assumed that

  • Postfix SMTP server and Dovecot IMAP server have been installed on your CentOS 8/RHEL 8 server
  • You have already installed a LAMP stack or LEMP stack on CentOS 8/RHEL 8 server.

If not, please click the above links and follow the instructions to complete prerequisites. Now let’s proceed to install Roundcube.

Step 1: Download Roundcube Webmail on CentOS 8/RHEL 8

Log in to your CentOS/RHEL server via SSH, then run the following command to download the latest 1.4.9 stable version from Roundcube Github repository.


Note: You can always use the above URL format to download Roundcube from command line. If a new version comes out, simply replace 1.4.9 with the new version number. You can check if there’s new release at Roundcube download page.

Extract the tarball,  move the newly created folder to web root (/var/www/) and rename it as roundcube at the same time.

tar xvf roundcubemail-1.4.9-complete.tar.gz

sudo mkdir /var/www/

sudo mv roundcubemail-1.4.9 /var/www/roundcube

Step 2: Install Dependencies

Roundcube requires the php-imap module to create subfolders in mailboxes, but php-imap isn’t included in the default CentOS 8/RHEL 8 repository, so we need to use the Remi repo to install this PHP module.

Install the Remi Repo.

sudo dnf install -y

Then reset PHP module streams.

sudo dnf module reset php

Enable the php:remi-7.4 module stream.

sudo dnf module enable php:remi-7.4 -y

Then you can run the following command to install PHP modules required or recommended by Roundcube.

sudo dnf install php-ldap php-imagick php-common php-gd php-imap php-json php-curl php-zip php-xml php-mbstring php-bz2 php-intl php-gmp

Step 3: Create a MariaDB Database and User for Roundcube

Log into MariaDB shell as root.

mysql -u root -p

Then create a new database for Roundcube using the following command. This tutorial name it roundcube, you can use whatever name you like for the database.


Next, create a new database user on localhost using the following command. Again, this tutorial name it roundcubeuser, you can use whatever name you like. Replace password with your preferred password.

CREATE USER [email protected] IDENTIFIED BY 'password';

Then grant all permission of the new database to the new user so later on Roundcube webmail can write to the database.

GRANT ALL PRIVILEGES ON roundcube.* TO [email protected];

Flush the privileges table for the changes to take effect.

flush privileges;

Exit MariaDB Shell:


Run the following command to import the initial tables to roundcube database. You need to enter the MariaDB root password.

mysql -u root -p roundcube < /var/www/roundcube/SQL/mysql.initial.sql

Step 4: Create Apache Virtual Host or Nginx Config File for Roundcube


If you use Apache web server, create a virtual host for Roundcube.

sudo nano /etc/httpd/conf.d/roundcube.conf

Note: If you followed my Postfix/Dovecot tutorial, a virtual host already exists. You should edit the following file. (Remove the texts in this file that was added in part 2 and add the new texts below.)

sudo nano /etc/httpd/conf.d/

Put the following text into the file. Replace with your real domain name and don’t forget to set DNS A record for it.

<VirtualHost *:80>
  DocumentRoot /var/www/roundcube/

  ErrorLog /var/log/httpd/roundcube_error.log
  CustomLog /var/log/httpd/roundcube_access.log combined

  <Directory />
    Options FollowSymLinks
    AllowOverride All

  <Directory /var/www/roundcube/>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all


Save and close the file. Reload Apache for the changes to take effect.

sudo systemctl reload httpd

Now you should be able to see the Roundcube web-based install wizard at


If you use Nginx web server, create a virtual host for Roundcube.

sudo nano /etc/nginx/conf.d/roundcube.conf

Note: If you followed my Postfix/Dovecot tutorial, a virtual host already exists. you should edit the following file. (Remove the texts in this file that was added in part 2 and add the new texts below.)

sudo nano /etc/nginx/conf.d/

Put the following text into the file. Replace the domain name and don’t forget to set DNS A record for it.

server {
  listen 80;
  listen [::]:80;
  root /var/www/roundcube/;
  index index.php index.html index.htm;

  error_log /var/log/nginx/roundcube.error;
  access_log /var/log/nginx/roundcube.access;

  location / {
    try_files $uri $uri/ /index.php;

  location ~ .php$ {
   try_files $uri =404;
    fastcgi_pass unix:/run/php-fpm/www.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

  location ~ /.well-known/acme-challenge {
    allow all;
    deny all;
  location ~ ^/(bin|SQL)/ {
    deny all;
 # A long browser cache lifetime can speed up repeat visits to your page
  location ~* .(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log        off;
       log_not_found     off;
       expires           360d;

Save and close the file. Then test Nginx configurations.

sudo nginx -t

If the test is successful, reload Nginx for the changes to take effect.

sudo systemctl reload nginx

Now you should be able to see the Roundcube web-based install wizard at

Step 5: Enabling HTTPS

It’s highly recommended that you use TLS to encrypt your webmail. We can enable HTTPS by installing a free TLS certificate issued from Let’s Encrypt.

If you use Apache, run this command to obtain and install TLS certificate.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d

If you use Nginx, run the following command to obtain and install TLS certificate.

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d


  • --nginx: Use the nginx plugin.
  • --apache: Use the Apache plugin.
  • --agree-tos: Agree to terms of service.
  • --redirect: Force HTTPS by 301 redirect.
  • --hsts: Add the Strict-Transport-Security header to every HTTP response. Forcing browser to always use TLS for the domain. Defends against SSL/TLS Stripping.
  • --staple-ocsp: Enables OCSP Stapling. A valid OCSP response is stapled to the certificate that the server offers during TLS.

The certificate should now be obtained and automatically installed.

Note: If you followed my Postfix/Dovecot tutorial, and now you install Roundcube on the same server, then certbot will probably tell you that a certificate for already exists as shown below, so you can choose to install the existing TLS certificate to your web server configuration file.

roundcube postfix dovecot certbot https certificate centos

Step 6: Setting Up Permissions

First, we need to change the SELinux context of the web directory, so it can be used to serve web content.

sudo chcon -t httpd_sys_content_t /var/www/roundcube/ -R

The web server needs to write to the temp and logs directory. Change the SELinux context to make it writable.

sudo chcon -t httpd_sys_rw_content_t /var/www/roundcube/temp/ /var/www/roundcube/logs/ -R

Then grant write permission to the web server.


sudo setfacl -R -m u:apache:rwx /var/www/roundcube/temp/ /var/www/roundcube/logs/


sudo setfacl -R -m u:nginx:rwx /var/www/roundcube/temp/ /var/www/roundcube/logs/

By default, SELinux forbids Apache/Nginx to make network requests to other servers, but later Apache/Nginx needs to request TLS certificate status from Let’s Encrypt CA server for OCSP stapling, so we need to tell SELinux to allow Apache/Nginx with the following command.

sudo setsebool -P httpd_can_network_connect 1

If you use Nginx, then you also need to run the following command to give the nginx user read and write permissions to 3 directories.

sudo setfacl -R -m u:nginx:rwx /var/lib/php/opcache/ /var/lib/php/session/ /var/lib/php/wsdlcache/

Restart Apache/Nginx.

sudo systemctl restart httpd

sudo systemctl restart nginx

Step 7: Finish the Installation in Web Browser

In your web browser, go to the Roundcube installer page.

The web installer will first check if PHP extensions, database and 3rd party libraries are installed. If you follow this tutorial, then all requirements should be met.

roundcube-centos 8

Click Next button. In the 2nd page, you need to fill in MariaDB database details that you created in step 3.

roundcube mariadb user

The IMAP and SMTP section allows you to configure how to receive and submit email. Enter the following values for IMAP.

  • IMAP host: ssl://  port: 993

roundcube imap settings

Enter the following values for SMTP settings.

  • SMTP port: tls://  port: 587

roundcube smtp settings


Next, you can scroll down to the Plugins section to enable some plugins. For example: the password plugin, mark as junk plugin and so on. I enabled all of them.

roundcube enable plugins

Once that’s done, click create config button which will create configuration based on the information you entered. You need to copy the configuration and save it as under the /var/www/roundcube/config/ directory.

roundcube webmail installer

Once the file is created, click continue button. In the final step, test your SMTP and IMAP settings by sending a test email and checking IMAP login. Note that you need to enter your full email address in the Sender field when testing SMTP config.

roundcube webmail test smtp & imap config

If the test fails, then you can click the 2. Create config link on the top of page to go back to step 2 and recreate the file.

If test is successful, go to your Webmail domain without /installer and login.

roundcube webmail elastic skin

Roundcube Webmail interface

roundcube ubuntu server apache nginx

Now you should remove the whole installer folder from the document root or make sure that enable_installer option in file is disabled.

sudo rm /var/www/roundcube/installer/ -r

These files may expose sensitive configuration data like server passwords and encryption keys to the public. Make sure you cannot access the installer page from your browser.

Step 8: Configure the Sieve Message Filter

You can create folders in Roundcube webmail and then create rules to filter email messages into different folders. In order to do this, you need to install the dovecot-pigeonhole package with the following command.

sudo dnf install dovecot-pigeonhole

Open the /etc/dovecot/conf.d/15-lda.conf file.

sudo nano /etc/dovecot/conf.d/15-lda.conf

Scroll to the end of the file, uncomment the mail_plugins line and add the sieve plugin to local delivery agent (LDA).

protocol lda {
    # Space separated list of plugins to load (default is global mail_plugins).
    mail_plugins = $mail_plugins sieve

Save and close the file. If you can find the 20-lmtp.conf file under /etc/dovecot/conf.d/ directory, then you should also enable the sieve plugin in that file like below.

protocol lmtp {
      mail_plugins = quota sieve

Edit the /etc/dovecot/conf.d/10-mail.conf file.

sudo nano /etc/dovecot/conf.d/10-mail.conf

Sieve scripts are stored under each user’s home directory. If you followed my PostfixAdmin tutorial and are using virtual mailbox domains, then you need to enable mail_home for the virtual users by adding the following line in the file, because virtual users don’t have home directories by default.

mail_home = /var/vmail/%d/%n

Save and close the file.

By default, Postfix uses its builtin local delivery agent (LDA) to move inbound emails to the message store (inbox, sent, trash, Junk, etc). We can configure it to use Dovecot to deliver emails, via the LMTP protocol, which is a simplified version of SMTP. LMTP allows for a highly scalable and reliable mail system and it is required if you want to use the sieve plugin to filter inbound messages to different folders.

Edit the Dovecot main configuration file.

sudo nano /etc/dovecot/dovecot.conf

Add lmtp and sieve to the supported protocols.

protocols = imap lmtp sieve

Save and close the file. Then edit the Dovecot 10-master.conf file.

sudo nano /etc/dovecot/conf.d/10-master.conf

Change the lmtp service definition to the following.

service lmtp {
 unix_listener /var/spool/postfix/private/dovecot-lmtp {
   group = postfix
   mode = 0600
   user = postfix

Next, edit the Postfix main configuration file.

sudo nano /etc/postfix/

Add the following lines at the end of the file. The first line tells Postfix to deliver emails to local message store via the dovecot LMTP server.  The second line disables SMTPUTF8 in Postfix, because Dovecot-LMTP doesn’t support this email extension.

mailbox_transport = lmtp:unix:private/dovecot-lmtp
smtputf8_enable = no

Save and close the file. Finally, restart Postfix and Dovecot.

sudo systemctl restart postfix dovecot

Now you can go to Roundcube webmail, open an email message and click the more button and select create filters to create message filters. For example, I create a filter that moves every email sent from to the Red Hat folder.

roundcube sieve filter

Note that if you move a sieve filter set from an old mail server to your new mail server, you need to go to Settings -> Filters, then click Actions and enable the filter set, or Dovecot LMTP server won’t execute the sieve filter.

Step 9: Adding Local DNS Entry

It’s recommended to edit the /etc/hosts file and add the following entry so that Roundcube won’t have to query the public DNS, which will speed up web page loading a little bit.  localhost

Step 10: Removing Sensitive Information from Email Headers

By default, Roundcube will add a User-Agent email header, indicating that you are using Roundcube webmail and the version number. You can tell Postfix to ignore it so recipient can not see it. Run the following command to create a header check file.

sudo nano /etc/postfix/smtp_header_checks

Put the following lines into the file.

/^User-Agent.*Roundcube Webmail/            IGNORE

Save and close the file. Then edit the Postfix main configuration file.

sudo nano /etc/postfix/

Add the following line at the end of the file.

smtp_header_checks = regexp:/etc/postfix/smtp_header_checks

Save and close the file. Then run the following command to rebuild hash table.

sudo postmap /etc/postfix/smtp_header_checks

Reload Postfix for the change to take effect.

sudo systemctl reload postfix

Now Postfix won’t include User-Agent: Roundcube Webmail in the headers when sending outgoing emails.

Step 11: Configure the Password Plugin in Roundcube

Roundcube includes a password plugin that allows users to change their password from the webmail interface. However, we need to configure it before it will work. Edit the password plugin configuration file.

sudo nano /var/www/roundcube/plugins/password/

If your Roundcube doesn’t have the file, then copy the default config file and edit the file.

cd /var/www/roundcube/plugins/password/
sudo cp
sudo nano

Find the following line:

$config['password_db_dsn'] = '';

This parameter is used to tell the password plugin where the user passwords are stored. By default, the value is empty and it will query the roundcube database, which doesn’t store user passwords. If you followed my PostfixAdmin tutorial, then user passwords are stored in the postfixadmin database, so we need to change the value to:

$config['password_db_dsn'] = 'mysql://postfixadmin:[email protected]/postfixadmin';

The tells the password plugin to connect to the postfixadmin database. If you don’t remember your postfixadmin database password, you can find it in the /etc/dovecot/dovecot-sql.conf.ext file.

Then find the following line.

$config['password_query'] = 'SELECT update_passwd(%c, %u)';

Change it to the following.

$config['password_query'] = "UPDATE mailbox SET password=%D,modified=NOW() WHERE username=%u";

I recommend enabling a password strength checker to prevent users from setting week passwords. Go to the beginning of this file, you can find the following line.

$config['password_strength_driver'] = null;

We can use the zxcvbn password strength driver, so change it to:

$config['password_strength_driver'] = 'zxcvbn';

Add the following line in this file to allow strong passwords only.

$config['password_zxcvbn_min_score'] = 5;

Note: The $config['password_minimum_score'] parameter doesn’t work with the zxcvbn driver, so leave it alone.

You can also set a minimum length for the password. Find the following line.

$config['password_minimum_length'] = 0;

Change it to:

$config['password_minimum_length'] = 8;

Recall that we used the BLF-CRYPT password scheme in the PostfixAdmin tutorial, so we also need to configure the password plugin to use BLF-CRYPT. Find the following lines in the file.

$config['password_algorithm'] = 'clear';

By default, the password will be stored as clear text, change the value to the following to use Dovecot’s builtin password algorithm.

$config['password_algorithm'] = 'dovecot';

Then find the following line, which tells where the Dovecot’s password hash generator is located.

$config['password_dovecotpw'] = '/usr/local/sbin/dovecotpw'; // for dovecot-1.x

Change it to the following.

$config['password_dovecotpw'] = '/usr/bin/doveadm pw -r 12';

Then find the following line, which tells which password scheme will be used.

$config['password_dovecotpw_method'] = 'CRAM-MD5';

Change it to:

$config['password_dovecotpw_method'] = 'BLF-CRYPT';

Find the following line.

$config['password_dovecotpw_with_method'] = false;

Change false to true. This will add a {BLF-CRYPT} prefix to the hashed password, so you will recognize which password scheme is used.

$config['password_dovecotpw_with_method'] = true;

Save and close the file. Since this file contains the database password, we should allow only the web server user to read and write to this file.


sudo chown apache:apache /var/www/roundcube/plugins/password/
sudo chmod 600 /var/www/roundcube/plugins/password/


sudo chown nginx:nginx /var/www/roundcube/plugins/password/
sudo chmod 600 /var/www/roundcube/plugins/password/

Now users should be able to change their passwords in the Roundcube webmail interface.

roundcube webmail change password

How to Set Up Vacation/Out-of-Office Messages

We can use the sieve filter to create vacation/out-of-office messages. Go to Roundcube Settings -> Filters. Then click the create button to create a filter.

  • Give this filer a name like “out of office”.
  • New filters are not disabled, so you can leave the button alone.
  • In the Scope field, select all messages.
  • Select Replay with message in the Actions settings, and enter the message that will be automatically sent.
  • Enter 1 in how ofter send messages. Leave other text field empty.
  • Click the Save button and you are done.

roundcube vacation out of office message

When you are back to office, you can toggle the “Filter disabled” button, and click the Save button to disable this filter.

Setting Up Multiple Mail Domains

To host multiple mail domains, please read the following article:

  • How to Host Multiple Mail Domains in PostfixAdmin on CentOS/RHEL

Troubleshooting Tips

If you encounter errors, you can check the web server error logs at /var/log/apache2/roundcube_error.log (if you are using Apache), or /var/log/nginx/roundcube.error (if you are using Nginx.), also the Roundcube error logs in /var/www/roundcube/logs/ directory.

Wrapping Up

I hope this tutorial helped you install Roundcube Webmail on CentOS 8/RHEL 8. As always, if you found this post useful,  subscribe to our free newsletter to get more tips and tricks 🙂