Install and Setup Roundcube Webmail on Debian 12/11/10

|
Last Updated:
|
|

In this tutorial, you will learn how to install and setup Roundcube webmail on Debian 12/11/10. 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.

Installing Roundcube Webmail on Debian 12/11/10

What are the Features Provided by Roundcube

Roundcube webmail 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.

Prerequisites for Running Roundcube

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

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

apt install apache2 libapache2-mod-php -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 Debian 12/11/10

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

Install MariaDB 10 on Debian 12

Install PHP 8 on Debian 12/11/10

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

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

apt install php php-mcrypt php-mysql php-gd php-xml \
php-mbstring php-intl php-zip php-json php-pear \
php-curl php-imagick openssl composer -y

On Debian 11 and Debian 10, use the guide below to install PHP 8.

Install PHP 8.0/8.1/8.2/8.x on Debian 11/Debian 10

You can then install the required PHP 8 modules;

apt install php php-{mcrypt,mysql,gd,xml,mbstring,intl,zip,json,pear,curl,imagick } openssl composer -y

On Debian 12/11/10, install PEAR packages

pear channel-update pear.php.net
pear install Net_SMTP Net_IDNA2-0.1.1 Mail_mime Mail_mimeDecode
pear install channel://pear.php.net/Auth_SASL2-0.2.0

Install Roundcube Webmail on Debian 12/11/10

Run System Package Cache Update

Before you can proceed with installation and configuration of Roundcube webmail on Debian12/11/10, update and upgrade your server packages;

apt update

Download Roundcube

As much as Roundcube could be available on the default Debian repositories, it is usually not upto date.

For example, these are the available versions on Debian default repos as of this writing;

apt-cache policy roundcube

Debian 12;

roundcube:
  Installed: (none)
  Candidate: 1.6.1+dfsg-1
  Version table:
     1.6.1+dfsg-1 500
        500 http://deb.debian.org/debian bookworm/main amd64 Packages

Debian 11;

roundcube:
  Installed: (none)
  Candidate: 1.4.13+dfsg.1-1~deb11u1
  Version table:
     1.4.13+dfsg.1-1~deb11u1 500
        500 http://deb.debian.org/debian bullseye/main amd64 Packages
        500 http://security.debian.org/debian-security bullseye-security/main amd64 Packages

Debian 10;

roundcube:
  Installed: (none)
  Candidate: 1.3.17+dfsg.1-1~deb10u2
  Version table:
     1.3.17+dfsg.1-1~deb10u2 500
        500 http://deb.debian.org/debian buster/main amd64 Packages
        500 http://security.debian.org/debian-security buster/updates/main amd64 Packages

If the stable current release version is available, then by all means, install Roundcube using the APT package manager directly from repos.

Otherwise, the latest stable release version for Roundcube can be installed by downloading the source code from the Roundcube downloads page. Download the Complete package under the Stable version section. Once you get the link, you can simply download it as shown below;

Replace the value of the VER variable with the current release version number;

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

You can calculate the SHA-256 hash value and compare with the value on the downloads page. Ensure the values match.

Extract Roundcube Package Archive to Webroot Directory

Extract the Roundcube tarball archive to the web root directory.

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

You should now have Roundcube configs and directories under /var/www/roundcube/;

ls -1 /var/www/roundcube/
bin
CHANGELOG.md
composer.json
composer.json-dist
composer.lock
config
index.php
INSTALL
installer
LICENSE
logs
plugins
program
public_html
README.md
SECURITY.md
skins
SQL
temp
UPGRADING
vendor

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

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

The /config, /temp and /logs directories should be protected.

If UFW is running, allow Apache2.

ufw allow WWW

OR allows both HTTP and HTTPs

ufw allow "WWW Full"  

Configure Apache for Roundcube

Next, it is wise to create a dedicated Apache virtualhost configuration file for Roundcube instead of editing the default Apache configuration. To create one see below;

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

Update the content below and copy, and paste into the configuration file above.

<VirtualHost *:80>
        ServerName roundcube.kifarunix-demo.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/roundcube

	<Directory /var/www/roundcube>
		Options +FollowSymLinks
		AddType text/x-component .htc
		<IfModule mod_php8.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
		Order allow,deny
		Allow from all
	</Directory>
	
	<Directory /var/www/roundcube/plugins/enigma/home>
		Options -FollowSymLinks
		AllowOverride None
		Order allow,deny
		Deny from all
	</Directory>
	<Directory /var/www/roundcube/config>
		Options -FollowSymLinks
		AllowOverride None
		Order allow,deny
		Deny from all
	</Directory>
	<Directory /var/www/roundcube/temp>
		Options -FollowSymLinks
		AllowOverride None
		Order allow,deny
		Deny from all
	</Directory>
	<Directory /var/www/roundcube/logs>
		Options -FollowSymLinks
		AllowOverride None
		Order allow,deny
		Deny from all
	</Directory>
        ErrorLog ${APACHE_LOG_DIR}/roundcube-error.log
        CustomLog ${APACHE_LOG_DIR}/roundcube-access.log combined
</VirtualHost>

Save and quit the configuration file.

Verify syntactical errors in Rouncube site configuration.

apachectl -t

Ensure output is Syntax OK.

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

Disable Apache default site and enable Roundcube site.

a2dissite 000-default
a2ensite roundcube

Enable the following Apache Modules

a2enmod deflate expires headers rewrite

Restart Apache if there is error.

systemctl restart apache2

Database Configuration

Run the MySQL basic secure script to set the root password, remove test databases, disable remote root login and remove anonymous users.

mysql_secure_installation

Create Roundcube database and and grant privileges to a separate database user.

Be sure to replace the database, username and password accordingly.

mysql -u root -p -e "create database roundcube;"
mysql -u root -p -e "create user admin@localhost identified by 'ChangeME';"
mysql -u root -p -e "grant all privileges on roundcube.* to admin@localhost;"

Run the command below to reload the database tables and effect the changes made above. Quit the database after that.

mysql -u root -p -e 'flush privileges';

Import the Roundcube data to the newly created database above;

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

Configure PHP

Run the command below to enable PHP mbstring, xml and dom modules respectively.

phpenmod mbstring xml dom mcrypt intl

Verify with the command;

php -m | egrep "mbs|int|dom|xml"
dom
intl
libxml
mbstring
random
xml
xmlreader
xmlwriter

Edit the /etc/php/8.2/apache2/php.ini and set the timezone

sed -i 's/^;date.timezone =/date.timezone = US\/Alaska/g' /etc/php/8.2/apache2/php.ini

Configure Roundcube on Debian 12/11/10

Create Rouncube configuration file based on the sample configuration file. You can simply copy the sample config as shown below;

sudo -u www-data cp /var/www/roundcube/config/config.inc.php{.sample,}

Open the configuration file for editing and put the contents below;

vim /var/www/roundcube/config/config.inc.php

Set the database connection string. Replace the details with your database connection details set above.

$config['db_dsnw'] = 'mysql://admin:ChangeME@localhost/roundcube';

Next, define your Email server IMAP and SMTP addresses. We use Gmail as our email server in this demo (You will need app password);

// IMAP host chosen to perform the log-in.
// See defaults.inc.php for the option description.
$config['imap_host'] = 'ssl://imap.gmail.com:993';

// SMTP server host (for sending mails).
// See defaults.inc.php for the option description.
$config['smtp_host'] = 'tls://smtp.gmail.com:587';

// SMTP username (if required) if you use %u as the username Roundcube
// will use the current username for login
$config['smtp_user'] = '%u';

// SMTP password (if required) if you use %p as the password Roundcube
// will use the current user's password for login
$config['smtp_pass'] = '%p';

We will leave the other default settings.

Save and exit the file.

If you need to find more description of the options in the config above, then check the /var/www/roundcube/config/defaults.inc.php.

You can as well check our previous article on how to setup a fully fledged mail server with iRedMail on Ubuntu 18.04.

Restart Apache

service apache2 restart

Btw, if you want to test the connection for Email and Database, enable the installer in the Roundcube configuration;

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

Restart Apache and access the installer from the browser to test the connections;

http://roundcube.kifarunix-demo.com/installer

After everything works fine, then remove the installer;

sed -i '/enable_installer/s/^/#/g' /var/www/roundcube/config/config.inc.php

Accessing Roundcube Web Interface

You are now ready to access Roundcube web interface. Navigate to http://roundcube.example.com and log in using your email account’s username and password.

Install and Setup Roundcube Webmail on Debian
Install and Setup Roundcube Webmail on Debian

You have successfully install and setup your Roundcube webmail client and you can now be able to accessible you emails normally.

That closes our guide on how to install and setup Roundcube webmail on Debian 12/11/10.