This is an old revision of the document!


Installation

Note that there is an installer script which performs the steps below. Currently it supports fresh, minimal installed Debian 7.

Prerequisites

Mandatory:
  • Install a supported anti-virus application. See the antivirus support page for the details.

Optional:

Using Debian

On a fresh Debian installation get the following packages:

apt-get install \
           openssl \
           libssl-dev \
           gcc \
           g++ \
           make \
           sysstat \
           libtre-dev \
           php5-cli \
           php5-cgi \
           php5-mysql \
           php5-fpm \
           php5-ldap \
           php5-gd \
           php5-xcache \
           php5-curl \
           libwrap0-dev \
           libmysqlclient-dev \
           libzip-dev \
           nginx \
           mysql-server \
           clamav-daemon

Create a dedicated and non-privileged user to run run clapf

groupadd clapf
useradd -g clapf -s /bin/sh -d /var/clapf clapf
usermod -L clapf

Unpack and compile clapf

tar zxvf clapf-x.y.z.tar.gz
cd clapf-x.y.z
./configure \
        --localstatedir=/var \
        --with-database=mysql \
        --enable-clamd

make
su -c 'make install'

Hint: use gmake on FreeBSD.

Setup the database

Create a dedicated MySQL user and database:

#mysql -u root -p
mysql>create database clapf character set 'utf8';
mysql>grant all privileges on clapf.* to clapf@localhost identified by 'verystrongpassword';
mysql>flush privileges;
mysql>quit;

Set the MySQL account parameters in clapf.conf:

mysqlhost=127.0.0.1
mysqlport=3306
mysqluser=clapf
mysqlpwd=verystrongpassword
mysqldb=clapf

If you want to connect via a Unix domain socket:

mysqlsocket=/var/run/mysql/mysql.sock
mysqluser=clapf
mysqlpwd=verystrongpassword
mysqldb=clapf

Important! Do not use *both* mysqlsocket and mysqlhost + mysqlport parameters.

If you have a larger installation, you may consider using a dedicated MySQL server box, since MySQL has a better performance if it does not have to compete with Postfix for I/O.

These are the recommended innodb settings, feel free to customise them:

[mysqld]
innodb_file_per_table
innodb_buffer_pool_size = 384M
innodb_support_xa=0
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=16M
innodb_log_file_size=16M
innodb_read_io_threads=4
innodb_write_io_threads=4
innodb_log_files_in_group=2

Finally, you may want to increase the 'max_allowed_packet' variable to allow large SQL queries:

[mysqld]
set-variable = max_allowed_packet=16M

To make MySQL even faster, consult the MySQL documentation.

Create the SQL schema for clapf

 mysql -u clapf -p clapf < util/db-mysql.sql

Perform the initial training

Before clapf is able to categorise emails, it must be trained. To do so collect a few thousands of good emails (ham) and spam emails. The spamdrop utility is able to train with a message, so assuming you have two directories with ham and spam emails in RFC-822 formatted EML files respectively, run the following two commands:

 for i in ham-dir/*; do spamdrop -H -m $i; done
 for i in spam-dir/*; do spamdrop -S -m $i; done

After that you should see lots of tokens in the token table, and the counters in the misc table represent the number of messages clapf has been trained on.

Choose a token group type

It can be either shared or merged

Start the clapf daemon

 /etc/init.d/rc.clapf start

Also make sure it starts everytime your server boots.

Setup the GUI

Rename sphinx.conf.dist to sphinx.conf, and fix the mysql and path settingss, then run the indexer utility as use clapf:

 # su - clapf
 $ indexer --all

Start searchd:

 /etc/init.d/rc.searchd start

Setup cron jobs for clapf

*/5 * * * * /usr/local/libexec/clapf/indexer.main.sh
2   2 * * * find /var/clapf/queue -type f -ctime +30 -exec rm -f '{}' \;

Configure the mail server

What next?

You may be interested in the RBL support, whitelist feature, minefield (or blackhole), making some statistics, or some of the anti-spam details.