Compile and Install Exim from Source with LDAP and MySQL Lookup Support on Ubuntu 14.04

We’re moving an existing Exim 4.72 installation from Debian Squeeze to Ubuntu 14.04 (Ubuntu 14.04 comes with Exim 4.82).

Starting with Exim 4.77, a match_* no longer expand right-hand-side by default. However, Exim provides a new compile-time build option, EXPAND_LISTMATCH_RHS.

EXPAND_LISTMATCH_RHS is one of the reasons we are going to compile from source.

Note that this article does not cover Exim service configuration. If you need to configure Exim, you can do so by modifying the /etc/exim4/exim4.conf file.

Software

Software used in this article:

  1. Ubuntu 14.04
  2. Exim 4.82 (source code)
  3. Checkinstall 1.6

Pre-setup

Install Exim from repositories. This will create a Debian-exim user and group.

$ sudo apt-get install --no-install-recommends exim4-daemon-heavy

Also copy the following files. We’ll need them later:

$ cp /etc/init.d/exim4 ~/exim4.init
$ cp /etc/default/exim4 ~/exim4.default

Purge Exim:

$ sudo dpkg -P exim4-base exim4-daemon-heavy exim4-config

Exim from Source

Install dpkg-dev, checkinstall and pkg-config:

$ sudo apt-get install dpkg-dev checkinstall pkg-config

Get Exim’s source code:

$ mkdir ./exim-src && cd ./exim-src
$ apt-get source exim4

Install build dependencies:

$ sudo apt-get build-dep exim4

Configure Exim Build Options

Configure build options according to your needs:

$ cd ./exim4*
$ cp ./src/EDITME ./Local/Makefile
$ vim ./Local/Makefile

An example configuration is provided below:

$ grep -ve "^#" -ve "^$" ./Local/Makefile
BIN_DIRECTORY=/usr/sbin
CONFIGURE_FILE=/etc/exim4/exim4.conf
EXIM_USER=Debian-exim
EXIM_GROUP=Debian-exim
SPOOL_DIRECTORY=/var/spool/exim
ROUTER_ACCEPT=yes
ROUTER_DNSLOOKUP=yes
ROUTER_IPLITERAL=yes
ROUTER_MANUALROUTE=yes
ROUTER_QUERYPROGRAM=yes
ROUTER_REDIRECT=yes
ROUTER_IPLOOKUP=yes
TRANSPORT_APPENDFILE=yes
TRANSPORT_AUTOREPLY=yes
TRANSPORT_PIPE=yes
TRANSPORT_SMTP=yes
TRANSPORT_LMTP=yes
SUPPORT_MAILDIR=yes
SUPPORT_MAILSTORE=yes
SUPPORT_MBX=yes
LOOKUP_DBM=yes
LOOKUP_LSEARCH=yes
LOOKUP_DNSDB=yes
LOOKUP_CDB=yes
LOOKUP_DSEARCH=yes
LOOKUP_LDAP=yes
LOOKUP_MYSQL=yes
LOOKUP_NIS=yes
LOOKUP_NISPLUS=yes
LOOKUP_PASSWD=yes
LOOKUP_SQLITE=yes
LOOKUP_SQLITE_PC=sqlite3
LOOKUP_WILDLSEARCH=yes
LOOKUP_NWILDLSEARCH=yes
LDAP_LIB_TYPE=OPENLDAP2
PCRE_CONFIG=yes
LOOKUP_INCLUDE=-I /usr/local/ldap/include -I /usr/include/mysql
LOOKUP_LIBS=-L/usr/local/lib -lldap -llber -lmysqlclient -lpq -lsqlite3 -lm -ldl -lpam
WITH_CONTENT_SCAN=yes
WITH_OLD_DEMIME=yes
FIXED_NEVER_USERS=root
AUTH_CRAM_MD5=yes
AUTH_DOVECOT=yes
AUTH_PLAINTEXT=yes
AUTH_SPA=yes
HEADERS_CHARSET="ISO-8859-1"
HAVE_ICONV=yes
DEFAULT_CRYPT=crypt16
SUPPORT_TLS=yes
USE_GNUTLS=yes
USE_GNUTLS_PC=gnutls
DLOPEN_LOCAL_SCAN=yes
LDFLAGS += -rdynamic
CFLAGS += -fvisibility=hidden
LOG_FILE_PATH=/var/log/exim4/%slog
SYSLOG_LOG_PID=yes
EXICYCLOG_MAX=10
COMPRESS_COMMAND=/usr/bin/gzip
COMPRESS_SUFFIX=gz
ZCAT_COMMAND=/usr/bin/zcat
EXPAND_DLFUNC=yes
SUPPORT_PAM=yes
NO_SYMLINK=yes
SYSTEM_ALIASES_FILE=/etc/aliases
HAVE_IPV6=yes
TMPDIR="/tmp"
MAKE_SHELL=/bin/sh
SUPPORT_MOVE_FROZEN_MESSAGES=yes
EXPAND_LISTMATCH_RHS=yes

Optionally, if you need an Exim monitor, configure it too:

$ cp ./exim_monitor/EDITME ./Local/eximon.conf
$ vim ./Local/eximon.conf

Setup Exim Directories

We will need the following directories:

$ sudo mkdir -m 0755 /etc/exim4
$ sudo mkdir -m 0750 /var/log/exim4
$ sudo chown Debian-exim:Debian-exim /var/log/exim4
$ sudo mkdir -m 0750 /var/spool/exim
$ sudo chown Debian-exim:Debian-exim /var/spool/exim

Compile Source and Install Exim

Compile the source code:

$ make

Build a .deb package:

$ sudo checkinstall -D --install=no --pkgname exim4 --pkgrelease $(date +%F) \
--maintainer "[email protected]" --strip=no --stripso=no --addso=yes --nodoc

Install the package:

$ sudo dpkg -i ./exim4*deb

Check Exim version and modules:

$ exim -bV
Exim version 4.82 #3 built 24-Feb-2015 18:10:38
Copyright (c) University of Cambridge, 1995 - 2013
(c) The Exim Maintainers and contributors in ACKNOWLEDGMENTS file, 2007 - 2013
Berkeley DB: Berkeley DB 5.3.28: (September  9, 2013)
Support for: crypteq iconv() IPv6 PAM Expand_dlfunc GnuTLS move_frozen_messages Content_Scanning DKIM Old_Demime
Lookups (built-in): lsearch wildlsearch nwildlsearch iplsearch cdb dbm dbmjz dbmnz dnsdb dsearch ldap ldapdn ldapm mysql nis nis0 nisplus passwd sqlite
Authenticators: cram_md5 dovecot plaintext spa
Routers: accept dnslookup ipliteral iplookup manualroute queryprogram redirect
Transports: appendfile/maildir/mailstore/mbx autoreply lmtp pipe smtp
Fixed never_users: 0
Size of off_t: 8
Configuration file is /etc/exim4/exim4.conf

Create Symbolic Links

From the Exim documentation:

Building and installing Exim does not of itself put it in general use. The name by which the system message transfer agent is called by mail user agents is either ‘/usr/lib/sendmail’, or ‘/usr/sbin/sendmail’ (depending on the operating system), and it is necessary to make this name point to the exim binary in order to get them to use it. This is normally done by renaming any existing file and making ‘/usr/lib/sendmail’ or ‘/usr/sbin/sendmail’ a symbolic link to the exim binary.

You may need the following symlinks:

$ sudo ln -s /usr/sbin/exim /usr/sbin/sendmail
$ sudo ln -s /usr/sbin/exim /usr/sbin/exim4
$ sudo mkdir /usr/lib/exim4
$ sudo ln -s /usr/sbin/exim /usr/lib/exim4/exim4

Start Exim

You can now start Exim by issuing the following command:

$ sudo /usr/sbin/exim4 -bd -q30m

Copy the files that were saved previously:

$ sudo cp ~/exim4.init /etc/init.d/exim4
$ sudo cp ~/exim4.default /etc/default/exim4

Now, you can also start Exim via:

$ sudo /etc/init.d/exim4 start

Leave a Reply

Your email address will not be published. Required fields are marked *