Roundcube is a powerful, browser-based IMAP mail client built with PHP. It offers a full suite of features you would normally expect from a desktop client—including PGP encryption, Sieve message filtering, address books, folder management, spell checking, and a mobile-responsive UI (the Elastic skin)—directly in your web browser.
Prerequisites
Before starting this installation, verify that your Ubuntu server has the following already configured:
- Mail Services: A working Postfix (SMTP) and Dovecot (IMAP) setup. (Note: If you deployed an all-in-one suite like iRedMail, Roundcube is likely already installed).
- Web Stack: A functional LAMP (Apache) or LEMP (Nginx) stack with MariaDB/MySQL.
- DNS: An
Arecord pointing your webmail subdomain (e.g.,mail.yourdomain.com) to your server’s public IP address.
1. Install PHP 8.1 and Required Extensions
Roundcube 1.6+ fully supports PHP 8.1. Add the Ondřej Surý PPA to ensure all required modules are available, then install the dependencies:
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install php-net-ldap2 php-net-ldap3 php-imagick php8.1-common php8.1-gd php8.1-imap php8.1-mysql php8.1-curl php8.1-zip php8.1-xml php8.1-mbstring php8.1-bz2 php8.1-intl php8.1-gmp php8.1-redis -y
2. Download and Prepare Roundcube Files
Connect to your server via SSH and fetch the complete Roundcube package from its official GitHub repository. (Tip: Check the Roundcube releases page and substitute 1.6.0 below if a newer patch is available).
wget https://github.com/roundcube/roundcubemail/releases/download/1.6.0/roundcubemail-1.6.0-complete.tar.gz
tar xvf roundcubemail-1.6.0-complete.tar.gz
sudo mkdir -p /var/www/
sudo mv roundcubemail-1.6.0 /var/www/roundcube
Grant the web server user (www-data) ownership over the temporary and logging directories:
sudo chown -R www-data:www-data /var/www/roundcube/temp/ /var/www/roundcube/logs/
3. Configure the MariaDB Database
Log into your MariaDB console:
sudo mysql -u root
Run the following SQL statements to create the database and user. (Note: Using roundcubemail consistently prevents schema import errors, and utf8mb4 ensures full modern Unicode support).
CREATE DATABASE roundcubemail DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'YourStrongPasswordHere';
GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Import the initial database schema into your newly created roundcubemail database:
sudo mysql -u root roundcubemail < /var/www/roundcube/SQL/mysql.initial.sql
(If your MariaDB root account requires a password, add the -p flag after root).
4. Configure Your Web Server
(Note: If you already have an existing virtual host configuration for mail.yourdomain.com from setting up Postfix/Dovecot, edit that file and replace its contents with the configuration below rather than creating a conflicting file).
Option A: Using Apache
Create or edit the virtual host file:
sudo nano /etc/apache2/sites-available/roundcube.conf
Insert the following configuration (updated to modern Apache 2.4 Require all granted syntax):
<VirtualHost *:80>
ServerName mail.yourdomain.com
DocumentRoot /var/www/roundcube/
ErrorLog ${APACHE_LOG_DIR}/roundcube_error.log
CustomLog ${APACHE_LOG_DIR}/roundcube_access.log combined
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/roundcube/>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Enable the site and reload Apache:
sudo a2ensite roundcube.conf
sudo systemctl reload apache2
Option B: Using Nginx
Create or edit the server block file:
sudo nano /etc/nginx/conf.d/roundcube.conf
Paste the following configuration:
server {
listen 80;
listen [::]:80;
server_name mail.yourdomain.com;
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/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.well-known/acme-challenge {
allow all;
}
# Block public access to sensitive documentation and scripts
location ~ ^/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
deny all;
}
location ~ ^/(bin|SQL)/ {
deny all;
}
# Static asset caching
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
}
Test the syntax and reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
5. Secure the Webmail Interface with Let’s Encrypt (HTTPS)
Encrypting webmail traffic is critical. Install Certbot along with your web server’s plugin:
For Apache:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email admin@yourdomain.com -d mail.yourdomain.com
For Nginx:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email admin@yourdomain.com -d mail.yourdomain.com
(If a certificate already exists for your mail hostname from your IMAP/SMTP setup, select the option to install/deploy the existing certificate into your web server configuration when prompted).
6. Optimize Local DNS Resolution
To prevent Roundcube from querying public DNS servers every time it communicates with your local mail server, map your mail hostname to localhost in /etc/hosts:
sudo nano /etc/hosts
Ensure the 127.0.0.1 line includes your mail domain:
127.0.0.1 localhost mail.yourdomain.com
7. Configure Roundcube Core Settings
Generate the active configuration file from the provided template:
cd /var/www/roundcube/config/
sudo cp config.inc.php.sample config.inc.php
sudo nano config.inc.php
Locate and update the following parameters in config.inc.php:
- Database Connection:
Replacepasswith your database password. (Important: If your password contains special characters like=, you must URL-encode them—for example,=becomes%3D).$config['db_dsnw'] = 'mysql://roundcube:YourStrongPasswordHere@localhost/roundcubemail'; - IMAP and SMTP Endpoints:
Configure TLS connections to your mail server:$config['imap_host'] = 'tls://mail.yourdomain.com:143'; $config['smtp_host'] = 'tls://mail.yourdomain.com:587'; - Encryption Key:
Replace the defaultdes_keywith a random 24-character string:$config['des_key'] = 'Generate24RandomCharsHere!'; - Plugins & Spellcheck:
Activate standard plugins (note thatdatabase_attachmentsis intentionally excluded in favor offilesystem_attachmentsto avoid database bloat and errors):$config['plugins'] = [ 'acl', 'additional_message_headers', 'archive', 'attachment_reminder', 'autologon', 'debug_logger', 'emoticons', 'enigma', 'filesystem_attachments', 'help', 'hide_blockquote', 'http_authentication', 'identicon', 'identity_select', 'jqueryui', 'krb_authentication', 'managesieve', 'markasjunk', 'new_user_dialog', 'new_user_identity', 'newmail_notifier', 'password', 'reconnect', 'redundant_attachments', 'show_additional_headers', 'squirrelmail_usercopy', 'subscriptions_option', 'userinfo', 'vcard_attachments', 'virtuser_file', 'virtuser_query', 'zipdownload' ];$config['enable_spellcheck'] = true;
Save and close the file. Verify that you can log in at https://mail.yourdomain.com, then immediately delete the installer directory to prevent unauthorized access to your server configuration:
sudo rm -rf /var/www/roundcube/installer/
8. Enable Server-Side Filtering & Vacation Auto-Replies (Sieve & LMTP)
To allow users to build inbox sorting rules and out-of-office replies, configure Postfix to hand off local delivery to Dovecot via LMTP, and enable ManageSieve.
- Install Sieve and LMTP packages:
sudo apt install dovecot-sieve dovecot-managesieved dovecot-lmtpd -y - Enable protocols in Dovecot:
Edit/etc/dovecot/dovecot.confand add:protocols = imap lmtp sieve - Configure the Dovecot LMTP socket:
Edit/etc/dovecot/conf.d/10-master.confand update theservice lmtpblock:service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { group = postfix mode = 0600 user = postfix } } - Route Postfix delivery through LMTP:
Edit/etc/postfix/main.cfand append the following to the bottom:mailbox_transport = lmtp:unix:private/dovecot-lmtp smtputf8_enable = no - Activate the Sieve plugin in Dovecot:
Open/etc/dovecot/conf.d/15-lda.conf, locate theprotocol ldasection, and enablesieve:protocol lda { mail_plugins = $mail_plugins sieve }(If/etc/dovecot/conf.d/20-lmtp.confexists on your system, open it and ensuremail_plugins = quota sieveis set insideprotocol lmtpas well). - Configure Virtual User Home Directories:
Sieve requires a home directory to store user scripts. If you use virtual mailboxes (e.g., via PostfixAdmin), open/etc/dovecot/conf.d/10-mail.confand ensuremail_homeis defined alongside yourmail_location:mail_home = /var/vmail/%d/%n - Restart mail services:
sudo systemctl restart postfix dovecot
- Creating Out-of-Office Auto-Replies: Users can now navigate to Settings -> Filters inside Roundcube, create a new filter scoped to All messages, set the action to Reply with message, and set the reply frequency to
1(or7days) per sender.
9. Strip Sensitive Client Headers from Outbound Mail
By default, outgoing emails include a User-Agent header advertising your Roundcube version. Strip this via Postfix header checks:
sudo nano /etc/postfix/smtp_header_checks
Add this regex rule:
/^User-Agent.*Roundcube Webmail/ IGNORE
Enable the check in /etc/postfix/main.cf by adding this line at the bottom:
smtp_header_checks = regexp:/etc/postfix/smtp_header_checks
Rebuild the Postfix lookup table and reload:
sudo postmap /etc/postfix/smtp_header_checks
sudo systemctl reload postfix
10. Configure the User Password Change Plugin
If you manage virtual mailboxes with PostfixAdmin and use ARGON2I password hashing, configure Roundcube’s password plugin so users can update their own passwords:
sudo cp /var/www/roundcube/plugins/password/config.inc.php.dist /var/www/roundcube/plugins/password/config.inc.php
sudo nano /var/www/roundcube/plugins/password/config.inc.php
Update the following parameters in /var/www/roundcube/plugins/password/config.inc.php:
// Connect to the PostfixAdmin database (check /etc/dovecot/dovecot-sql.conf.ext if you forgot the password)
$config['password_db_dsn'] = 'mysql://postfixadmin:postfixadmin_db_password@127.0.0.1/postfixadmin';
// SQL query to update the mailbox table
$config['password_query'] = 'UPDATE mailbox SET password=%P,modified=NOW() WHERE username=%u';
// Enforce strong passwords using zxcvbn
$config['password_strength_driver'] = 'zxcvbn';
$config['password_zxcvbn_min_score'] = 5;
$config['password_minimum_length'] = 8;
// Use Dovecot's native ARGON2I hashing
$config['password_algorithm'] = 'dovecot';
$config['password_dovecotpw'] = '/usr/bin/doveadm pw -r 5';
$config['password_dovecotpw_method'] = 'ARGON2I';
$config['password_dovecotpw_with_method'] = true;
Lock down the file permissions so only the web server can read the database credentials:
sudo chown www-data:www-data /var/www/roundcube/plugins/password/config.inc.php
sudo chmod 600 /var/www/roundcube/plugins/password/config.inc.php
11. Increase Attachment Upload Limits
By default, PHP restricts file uploads to 2MB and Nginx restricts body sizes to 1MB. Raise the limit to 50M (ensure this does not exceed Postfix’s message_size_limit):
Update PHP-FPM:
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /etc/php/8.1/fpm/php.ini
sudo sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /etc/php/8.1/fpm/php.ini
sudo systemctl restart php8.1-fpm
Update Nginx (if applicable):
Open /etc/nginx/conf.d/roundcube.conf (or mail.yourdomain.com.conf), add the following directive inside the server block, and reload Nginx:
client_max_body_size 50M;
sudo systemctl reload nginx
Upgrading Roundcube in the Future
When a newer release comes out, you can upgrade your installation in place without losing settings:
cd ~
wget https://github.com/roundcube/roundcubemail/releases/download/X.Y.Z/roundcubemail-X.Y.Z-complete.tar.gz
tar xvf roundcubemail-X.Y.Z-complete.tar.gz
sudo chown -R www-data:www-data roundcubemail-X.Y.Z/
sudo roundcubemail-X.Y.Z/bin/installto.sh /var/www/roundcube/
(Replace X.Y.Z with the target version number).
Quick Troubleshooting Checklist
- Where to check logs:
- Roundcube Logs:
/var/www/roundcube/logs/ - Mail Server Logs:
/var/log/mail.log - Web Server Logs:
/var/log/apache2/roundcube_error.logor/var/log/nginx/roundcube.error
- Roundcube Logs:
- “Connection to storage server failed” on login:
- Verify Dovecot is active (
sudo systemctl status dovecot). - Ensure your TLS certificate is valid and not self-signed or expired (
sudo certbot renew && sudo systemctl restart postfix dovecot). - Confirm the
/etc/hostslocal loopback entry from Step 6 is in place.
- Verify Dovecot is active (
- “Internal error: could not load message from server”:
- Usually caused by refreshing a URL pointing to a deleted message. Navigate back to the root domain (
https://mail.yourdomain.com).
- Usually caused by refreshing a URL pointing to a deleted message. Navigate back to the root domain (
- Sieve filters not triggering:
- Enable debugging by adding
mail_debug=yesto/etc/dovecot/dovecot.conf, restarting Dovecot, sending a test email, and inspecting/var/log/mail.logfor conflicting rules or missingmail_homepermissions. Also ensure the filter set is marked as Enabled under Settings -> Filters -> Actions.
- Enable debugging by adding
- “Temporary lookup failure (Code: 451)” when sending mail:
- Indicates Postfix cannot query your SQL database. Check
/var/log/mail.logand verify the database credentials inside/etc/postfix/sql/.
- Indicates Postfix cannot query your SQL database. Check
🚀 Ready to Master Your Own Self-Hosted Mail Server?
Setting up Roundcube is just one piece of the puzzle. If you want a complete, step-by-step video walkthrough covering DNS records, Postfix, Dovecot, spam filtering, DKIM/DMARC, and server security from scratch, check out my complete course!
👉 Enroll in “How to Set Up Your Own Mail Server on a VPS” on Udemy