Install and Setup Roundcube Webmail on Ubuntu 22.04/20.04

|
Last Updated:
|
|

In this tutorial, we are going to learn how to install and setup Roundcube webmail on Ubuntu 22.04/20.04. Roundcube webmail is a free and open source web-based IMAP email client. It is written in PHP and works just like any other email client.

What the are Features of Roundcube?

It provides a handful of features;

  • Full support for MIME and HTML messages
  • Sophisticated privacy protection
  • Compose messages with attachments
  • Multiple sender identities
  • Full featured address book with groups and LDAP connectors
  • Find-as-you-type address book integration
  • Richtext/HTML message composing
  • Forwarding messages with attachments
  • Searching messages and contacts
  • Spell checking

You can find comprehensive list of features of Roundcube here.

Installing Roundcube Webmail on Ubuntu 22.04/20.04

Prerequisites

As stated, Roundcube Webmail is written in PHP and thus it runs on a standard LAMPP server. The following are the minimum server requirements;

  • Apache, Lighttpd, Nginx, Cherokee or Hiawatha web server
  • PHP Version 7.3 or greater
  • MySQL, PostgreSQL, SQLite, MSSQL or Oracle database
  • SMTP server and IMAP server with IMAP4 rev1 support
  • PEAR packages distributed with Roundcube

Install Apache Web Server on Ubuntu

In this tutorial, we are going to use Apache as our web server. Therefore, follow through to install and configure it.

apt update
apt install apache2 -y

Apache is started and enabled by default after installation.

systemctl status apache2

If not running, then execute the command below to start and enable it to run on system boot;

systemctl enable --now apache2

Roundcube supports various database backends as stated above. In this guide, we are going to use MySQL.

Install MySQL/MariaDB on Ubuntu 22.04/20.04

MariaDB is available on default Debian repositories and can be installed as shown in this guide.

How to install MariaDB on Ubuntu

How to Install MySQL on Ubuntu

Install PHP 8 on Ubuntu

PHP is a server side scripting language that helps generate dynamic web content.

On Ubuntu 22.04;

To install PHP and all the requires dependencies for Roundcube, run the command below;

apt install openssl composer php-{net-smtp,mysql,gd,xml,mbstring,intl,zip,json,pear,bz2,gmp,\
imap,imagick,auth-sasl,mail-mime,net-ldap3,net-sieve,curl} libapache2-mod-php curl -y

On Ubuntu 20.04, to install PHP 8.2, you need additional Ondej Repo.

apt install software-properties-common ca-certificates lsb-release apt-transport-https 
add-apt-repository ppa:ondrej/php --yes
apt install openssl composer php-{net-smtp,mysql,gd,xml,mbstring,intl,zip,\
pear,bz2,gmp,imap,imagick,auth-sasl,mail-mime,net-ldap3,net-sieve,curl} \
libapache2-mod-php curl -y

Install Roundcube Webmail on Ubuntu 22.04/20.04

Download Roundcube

The latest stable release version for Roundcube can be installed by downloading the source code from the Roundcube downloads page.

NOTE that Rouncube is available on the default Ubuntu repos. However, the available version is not up-to-date.

As of this writing, Roundcube 1.6.2 is the latest stable release version. You can simply get the link and pull the tarball as follows;

Be sure to download the complete package.

VER=1.6.2
wget https://github.com/roundcube/roundcubemail/releases/download/${VER}/roundcubemail-${VER}-complete.tar.gz

Extract Roundcube to Apache Web Root Directory

Extract the Roundcube tarball archive to your web root directory, in our case, this directory is /var/www/html/roundcube.

Create this directory if it doesn’t exist.

mkdir /var/www/html/roundcube
tar xzf roundcubemail-${VER}-complete.tar.gz -C /var/www/html/roundcube --strip-components 1

Set proper ownership for roundcube root directory and permissions for Roundcube /temp and /logs directories;

chown -R www-data:www-data /var/www/html/roundcube/
chmod -R 775 /var/www/html/roundcube/{temp,logs}

The /config/temp and /logs directories should be protected against access from the browser.

Configure Apache VirtualHost for Roundcube

Create a dedicated Apache VirtualHost configuration file for Roundcube;

vim /etc/apache2/sites-available/roundcube.conf

Paste the content below.


<VirtualHost *:80>
        ServerName roundcube.kifarunix-demo.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/html/roundcube

	<Directory /var/www/html/roundcube>
		Options +FollowSymLinks
		AddType text/x-component .htc
		<IfModule mod_php.c>
			php_flag        display_errors  Off
			php_flag        log_errors      On
			php_value       upload_max_filesize     10M
			php_value       post_max_size           12M
			php_value       memory_limit            64M
			php_flag        zlib.output_compression         Off
			php_flag        magic_quotes_gpc                Off
			php_flag        magic_quotes_runtime            Off
			php_flag        zend.ze1_compatibility_mode     Off
			php_flag        suhosin.session.encrypt         Off
			php_flag        session.auto_start      Off
			php_value       session.gc_maxlifetime  21600
			php_value       session.gc_divisor      500
			php_value       session.gc_probability  1
		</IfModule>
		<IfModule mod_rewrite.c>
			RewriteEngine On
			RewriteRule ^favicon\.ico$ skins/larry/images/favicon.ico
			RewriteRule ^(?!installer)(\.?[^\.]+)$ - [F]
			RewriteRule ^/?(\.git|\.tx|SQL|bin|config|logs|temp|tests|program\/(include|lib|localization|steps)) - [F]
			RewriteRule /?(README\.md|composer\.json-dist|composer\.json|package\.xml)$ - [F]
		</IfModule>
		<IfModule mod_deflate.c>
			SetOutputFilter DEFLATE
		</IfModule>
		<IfModule mod_headers.c>
			# replace 'append' with 'merge' for Apache version 2.2.9 and later
			# Header append Cache-Control public env=!NO_CACHE
		</IfModule>
		<IfModule mod_expires.c>
			ExpiresActive On
			ExpiresDefault "access plus 1 month"
		</IfModule>
		FileETag MTime Size
		<IfModule mod_autoindex.c>
			Options -Indexes
		</ifModule>
		AllowOverride None
		Require all granted
	</Directory>
	
	<Directory /var/www/html/roundcube/plugins/enigma/home>
		Options -FollowSymLinks
		AllowOverride None
		Require all denied
	</Directory>
	<Directory /var/www/html/roundcube/config>
		Options -FollowSymLinks
		AllowOverride None
		Require all denied
	</Directory>
	<Directory /var/www/html/roundcube/temp>
		Options -FollowSymLinks
		AllowOverride None
		Require all denied
	</Directory>
	<Directory /var/www/html/roundcube/logs>
		Options -FollowSymLinks
		AllowOverride None
		Require all denied
	</Directory>
        ErrorLog ${APACHE_LOG_DIR}/roundcube-error.log
        CustomLog ${APACHE_LOG_DIR}/roundcube-access.log combined
</VirtualHost>

Save and quit the configuration file.

If you need to use HTTPS, obtain the SSL/TLS certificates and configure Apache appropriately.

Disable Apache default site

a2dissite 000-default

Enable Roundcube site.

a2ensite roundcube

Enable the following Apache Modules

a2enmod deflate expires headers rewrite

Verify syntactical errors in Rouncube site configuration.

apachectl -t
Syntax OK

If there are syntax errors, restart Apache if there is error.

systemctl restart apache2

Setup Roundcube Database

Create Roundcube Database and Database User

Roundcube supports various database backends as stated above.

In this guide, we are going to use MySQL server which we already installed in the guide whose link is given above.

Login to MySQL and create Roundcube databases.

systemctl enable --now mariadb
mysql -u root -p

Replace the database and database user names accordingly.

create database roundcube;

Create Roundcube database user and grant all privileges on Roundcube database.

create user rcadmin@localhost identified by 'StrongPassword';
grant all on roundcube.* to rcadmin@localhost;

Reload privileges tables and exit the database;

flush privileges;
quit

Import Roundcube initial database

Import Roundcube initial database into MySQL database created above;

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

Configure PHP for Roundcube

To begin, ensure the mbstring, xml, dom, intl PHP modules are enabled;

php -m | grep -iE "mbstring|xml|dom|intl"

Set default time zone in php.ini;

sed -i 's/^;date.timezone =/date.timezone = Asia\/Nicosia/' /etc/php/*/apache2/php.ini

And restart Apache;

systemctl restart apache2

Finalize Roundcube Webmail Setup on Ubuntu 22.04/20.04

You can now complete the setup of Roundcube from browser by accessing the http://server-IP-or-hostname/installer link.

Check the Prerequisites

When the installer runs, it first checks if all required dependencies are met. Ensure that everything is in an OK state before proceeding.

check roundcube php requirements

Database and other libs checks;

check database and required libs

Create Roundcube Configuration

Once all the requirements are met, go to the next step to create configuration for Roundcube.

For the General configuration and Logging & Debugging settings, let us go with the defaults.

Set the database connection settings as per what you created above.

database settings

For both IMAP and SMTP settings, we are using GMAIL relay. Hence just set the hosts and ports.

imap settings
smtp settings

For the rest of the settings, you can leave the defaults or update them to your preference.

Read more on the configurations page.

At the bottom of the page, CREATE CONFIG to create your Roundcube configuration with the options you have defined.

The configs are written to /var/www/html/roundcube/config/config.inc.php.

cat /var/www/html/roundcube/config/config.inc.php

<?php

/* Local configuration for Roundcube Webmail */

// ----------------------------------
// SQL DATABASE
// ----------------------------------
// Database connection string (DSN) for read+write operations
// Format (compatible with PEAR MDB2): db_provider://user:password@host/database
// Currently supported db_providers: mysql, pgsql, sqlite, mssql, sqlsrv, oracle
// For examples see http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php
// Note: for SQLite use absolute path (Linux): 'sqlite:////full/path/to/sqlite.db?mode=0646'
//       or (Windows): 'sqlite:///C:/full/path/to/sqlite.db'
// Note: Various drivers support various additional arguments for connection,
//       for Mysql: key, cipher, cert, capath, ca, verify_server_cert,
//       for Postgres: application_name, sslmode, sslcert, sslkey, sslrootcert, sslcrl, sslcompression, service.
//       e.g. 'mysql://roundcube:@localhost/roundcubemail?verify_server_cert=false'
$config['db_dsnw'] = 'mysql://rcadmin:StrongPassword@localhost/roundcube';

// ----------------------------------
// IMAP
// ----------------------------------
// The IMAP host (and optionally port number) chosen to perform the log-in.
// Leave blank to show a textbox at login, give a list of hosts
// to display a pulldown menu or set one host as string.
// Enter hostname with prefix ssl:// to use Implicit TLS, or use
// prefix tls:// to use STARTTLS.
// If port number is omitted it will be set to 993 (for ssl://) or 143 otherwise.
// Supported replacement variables:
// %n - hostname ($_SERVER['SERVER_NAME'])
// %t - hostname without the first part
// %d - domain (http hostname $_SERVER['HTTP_HOST'] without the first part)
// %s - domain name after the '@' from e-mail address provided at login screen
// For example %n = mail.domain.tld, %t = domain.tld
// WARNING: After hostname change update of mail_host column in users table is
//          required to match old user data records with the new host.
$config['imap_host'] = 'ssl://imap.gmail.com:993';

// ----------------------------------
// SMTP
// ----------------------------------
// SMTP server host (and optional port number) for sending mails.
// Enter hostname with prefix ssl:// to use Implicit TLS, or use
// prefix tls:// to use STARTTLS.
// If port number is omitted it will be set to 465 (for ssl://) or 587 otherwise.
// Supported replacement variables:
// %h - user's IMAP hostname
// %n - hostname ($_SERVER['SERVER_NAME'])
// %t - hostname without the first part
// %d - domain (http hostname $_SERVER['HTTP_HOST'] without the first part)
// %z - IMAP domain (IMAP hostname without the first part)
// For example %n = mail.domain.tld, %t = domain.tld
// To specify different SMTP servers for different IMAP hosts provide an array
// of IMAP host (no prefix or port) and SMTP server e.g. ['imap.example.com' => 'smtp.example.net']
$config['smtp_host'] = 'tls://smtp.gmail.com:587';

// provide an URL where a user can get support for this Roundcube installation
// PLEASE DO NOT LINK TO THE ROUNDCUBE.NET WEBSITE HERE!
$config['support_url'] = '';

// This key is used for encrypting purposes, like storing of imap password
// in the session. For historical reasons it's called DES_key, but it's used
// with any configured cipher_method (see below).
// For the default cipher_method a required key length is 24 characters.
$config['des_key'] = 'oHdGSqFPedBi919AL0Kfkwa5';

// ----------------------------------
// PLUGINS
// ----------------------------------
// List of active plugins (in plugins/ directory)
$config['plugins'] = [];

You should see a message that the configuration has been created successfully.

Click CONTINUE to proceed and Test the configuration.

Test your mail relay message deliverability by entering your email and password and click Send Test mail.

Test your message receivability, click Check login to verify.

You need to use App password for the Gmail Account.

Configure Postfix to Use Gmail App Passwords

test email settings roundcube

After completing the installation and the final tests remove the whole installer folder from the web root directory.

rm -rf /var/www/html/roundcube/installer/

You can simply disable the installer by running the command below;

echo "$config['enable_installer'] = false;" >> /var/www/html/roundcube/config/config.inc.php

Login to Roundcube Webmail

You can now access your Roundcube webmail via the address http://server-IP-or-hostname. This takes you to the login screen.

roundcube login

Use your email account credentials for logging in. In my case, am using my Gmail account.

roundcube dashboard

There you go. Roundcube is now up and running on Ubuntu 22.04/20.04. You can explore various functionalities of the tool further.

Further Reading

Roundcube HowTo wiki

How to Install and Setup Roundcube Webmail on Debian 12/11

Configure Sendmail to Use Gmail Relay on Ubuntu 18.04/Debian 10/9

How to Install and Setup iRedMail Mail Server on Ubuntu 18.04 LTS

Install Zimbra Mail Server on Fedora 30/29/CentOS 7

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment