Installing Roundcube on FreeBSD 6.1

This installation was done way back last year 2006 when I was still working for a government agency, I built this mail server for them. I had a free hand to choose whatever operating system I want so I chose FreeBSD, it was my first installation of FreeBSD and when I did it the release version was 6.1.

I will not discuss here about slices and partitioning and how I installed FreeBSD, instead I will discuss what applications are needed to be installed in order for Roundcube Webmail to work properly.

The following are the needed applications and how to install them:

Install MySQL:

# cd /usr/ports/databases/mysql41-server
# make install clean
# mysql_install_db

Change ownership of mysql directory:

# chown -R mysql /var/db/mysql/
# chgrp -R mysql /var/db/mysql/

Start MySQL server:

# /usr/local/bin/mysql_safe -user=mysql &

Note: If you encounter command not found error, just issue the command rehash.

# rehash

Make an initial my.cnf file by copying any of the examples:

# cp /usr/local/share/mysql/my-large.cnf /var/db/mysql/my.cnf

Install Apache 2.2:

# cd /usr/ports/www/apache22
# make install clean

Enable it at bootup:

# echo 'apache22_enable=”YES”' >> /etc/rc.conf

I used the default DocumentRoot which is located in /usr/local/www/apache22/data directory.

Install Dovecot:

# cd /usr/ports/mail/dovecot
# make install clean

Enable it at bootup:

# echo 'dovecot_enable=”YES”' >> /etc/rc.conf

We need to have a dovecot.conf file so copy the example.

# cd /usr/local/etc
# cp dovecot.conf.example dovecot.conf
# chmod u+w dovecot.conf

Edit dovecot.conf and add the following:

# vi dovecot.conf
	ssl_disable = no
	default_mail_env = maildir:/usr/home/%u/Maildir

Take note that default_mail_env can take an empty value, I chose the value above because it’s the settings I have in my Debian box.

Install Postfix:

# cd /usr/ports/mail/postfix-current
# make install clean

Note: You have to enable SASL2 and TLS fo security reasons.

Install PHP4 and PHP4-extensions:

# cd /usr/ports/lang/php4
# make install clean
# cd /usr/ports/lang/php4-extension
# make config
# make install clean

Note: If you’re going to use amavisd-new and postgrey, the application p5-BerkeleyDB is needed. This is how to install it.

# pkg_add -vr db41
# make install WITH_BDB_VER=41

Install SASL authentication daemon:

#  cd /usr/ports/security/cyrus-sasl2-saslauthd
# make install clean

Enable it at bootup:

# echo 'saslauthd_enable=”YES” >> /etc/rc.conf
# echo 'saslauthd_flags=”-a getpwent”' >> /etc/rc.conf

Install RoundCube:

I used svn to download and install roundcube based on fak3r’s howto.

Go to your Apache’s DocumentRoot:

# cd /usr/local/www/apache22/data

Checkout Roundcube using subversion:

# svn checkout https://svn.roundcube.net/trunk

Move the roundcubemail directory to your DocumentRoot, remove the ‘trunk’ directory and then change into the rouncubemail directory:

# mv trunk/roundcubemail .
# rm -rf trunk
# cd roundcubemail

Set permissions of the temp and logs dir so that the web user can read/write to them

# chown -R www:www temp logs

Create a database for storage of Roundcubemail data, replace $PASSWORD with the password you want the roundcube user to use to access mySQL.

Note: The initial mysql server install root password is blank, you must change this!

# mysql -u root -p
> create database 'roundcubemail';
> GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcube@localhost
IDENTIFIED BY '$PASSWORD';
> quit

Import the inital Roundcubemail SQL

# mysql roundcubemail < SQL/mysql.initial.sql

Change into the config directory

cd config

Copy the config *php.dist files to *.php

cp db.inc.php.dist db.inc.php
cp main.inc.php.dist main.inc.php

Modify the config files to suit your environment. In db.inc.php you only need to change the database definition line, add your password in place of $PASSWORD

$rcmail_config['db_dsnw'] = 'mysql://roundcube:PASSWORD@localhost/roundcubemail';

Assuming your mailserver is running on the same physical box as the webserver, disable database caching

$rcmail_config['enable_caching'] = FALSE;

define the host as localhost

$rcmail_config['default_host'] = 'localhost';

define smtp as localhost

$rcmail_config['smtp_server'] = 'localhost';

and increase the session lifetime from 5 to something more reasonable (optional)

$rcmail_config['session_lifetime'] = 30;

Launch a web browser and point it to

http://some.url/roundcubemail

Then login with a valid/existing IMAP username and password, since I did not use any table lookup for postfix, my roundcube users are the system users I’ve added using useradd utility and since they’re not going to use any shell, I disabled their login.

That’s all there is to it.

Cheers!