Installing Roundcube on Ubuntu 12.04 and 14.04

July 1st, 2013 Permalink

This post is a brief addendum to the long Ubuntu 12.04 mail server recipe I assembled last year. That uses Horde for webmail and I have become somewhat disenchanted with that package. If you need calendaring and other broad feature packages offered by Horde then it is probably worth wading through the Swamp of Infinite Configuration to get it working. If not, then there are simpler options, as outlined here. The directions provided below should also work as-is for Ubuntu 14.04.

Roundcube is a straightforward PHP webmail package, so it's easy enough to substitute Roundcube in place of Horde when building a mail server. The instructions you'll find online on how to install Roundcube are, shall we say, somewhat confused however. They will largely lead you down the wrong path if working from a package install on Ubuntu. Here instead is the quick and easy way to manage things, assuming that your mail server was built according to my guide, and thus has Apache and MySQL available.

Installation

Start by installing the necessary packages. The plugin packages aren't essential, but it doesn't hurt to look them over to see what is available. The additional PHP packages are needed to read some types of mail you might receive:

apt-get install --assume-yes \
  roundcube \
  roundcube-plugins \
  roundcube-plugins-extra \
  php-mail \
  php-mail-mimedecode \
  php-mime-type \
  php-mail-mime

In the package installation process you should choose to have the package set up the database for you. Pick MySQL as the database type. You'll be asked for the MySQL root user password, and to choose a password for the roundcube user that will be created.

Configuration

Set the following line in /var/lib/roundcube/config/main.inc.php:

// the mail host 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.
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// Supported replacement variables:
// %n - http hostname ($_SERVER['SERVER_NAME'])
// %d - domain (http hostname without the first part)
// %s - domain name after the '@' from e-mail address provided at login screen
// For example %n = mail.domain.tld, %d = domain.tld
$rcmail_config['default_host'] = 'localhost';

// TCP port used for IMAP connections
$rcmail_config['default_port'] = 143;

Using unencrypted connections is fine for communication between processes on the same host, as is the case here. If you built according to my guide you'll have set up encrypted access to IMAP as well and so could do this instead, though I think there is no need:

$rcmail_config['default_host'] = 'ssl://localhost';
$rcmail_config['default_port'] = 993;

At this point Roundcube is now installed and minimally configured, but it isn't accessible from the server webroot. The Roundcube webroot containing PHP files and various symlinks is sitting in /var/lib/roundcube, and the next step is to make that available to visitors.

Option 1: Roundcube in a Subfolder

If you have a busy webroot with other applications running, you may want to stick Roundcube into a subfolder, to be accessed via https://mail.example.com/roundcube or similar. This is easily accomplished by creating a symlink in the webroot:

ln -s /var/lib/roundcube /var/www/roundcube

If you have nothing in the upper directory of your webroot and want to redirect arrivals to the webmail login you might set up a redirect in /var/www/.htaccess:

RewriteRule ^/?$ /roundcube [L]

This has the advantage of leaving other subdirectories under /var/www accessible for whatever you might want to use them for, such as a Postfix Admin installation.

Option 2: Roundcube is the Webroot

An alternate approach is to switch the whole webroot over to /var/lib/roundcube, such that http://mail.example.com is the webmail login. In your site definition files under /etc/apache2/sites-enabled you'll want to change the DocumentRoot directive:

# Replace the standard webroot with the Roundcube directory.
# DocumentRoot /var/www/
DocumentRoot /var/lib/roundcube

This means that everything in /var/www/.htaccess, such rewrite rules to redirect all incoming traffic to SSL, must be copied and inserted into the existing Roundcube .htaccess file at /var/lib/roundcube/.htaccess. Don't just overwrite it as Roundcube needs its rules in order to function.

Any files and folders under /var/www must now be symlinked from /var/lib/roundcube, or they will now be inaccessible. For example if you are using Postfix Admin and have it set up at /var/www/postfixadmin then you would need to create this symlink:

ln -s /var/www/postfixadmin /var/lib/roundcube/postfixadmin