Difference between revisions of "Zarafa Installation On QNAP"

From QNAPedia
Jump to navigation Jump to search
Line 545: Line 545:
<h2>Hint for Zarafa QPKG users with Firmware 4.2.x</h2>
<h2>Hint for Zarafa QPKG users with Firmware 4.2.x</h2>
If you have installed the Zarafa QPKG 0.7.0 on firmware 4.2.x and only want to update the PHP MAPI extension to make it work with PHP 5.5 and/or the zarafa-* executables you can build Zarafa ontop of the QPKG using the description below.
If you have installed the Zarafa QPKG 0.7.0 on firmware 4.2.x and only want to update the PHP MAPI extension to make it work with PHP 5.5 you can build Zarafa ontop of the QPKG using the description below.
In this case libraries and include files in <tt>/usr/local/zarafa</tt> which have been installed by the Zarafa QKPG will be used instead of libraries from Optware (note that we still have to use the build tools from Optware).
In this case libraries and include files in <tt>/usr/local/zarafa</tt> which have been installed by the Zarafa QKPG will be used instead of libraries from Optware (note that we still have to use the build tools from Optware).

Revision as of 17:20, 21 October 2015

Currently there is some problem with editing QNAPedia articles. The page cannot be saved when it contains external links. Therefore as a workaround currently all links in this page are embedded as pure text and cannot be clicked. This will be changed as soon as the problem has been fixed by QNAPedia admins. See also http://forum.qnap.com/viewtopic.php?f=45&t=114992.


This is a report on how it is possible to build and install the Zarafa software (community edition, http://community.zarafa.com/) from source code on a QNAP TS-239 Pro-II NAS.

The Zarafa server is a groupware providing mail/contacts/calendar services. With Z-Push (http://z-push.org) one can even add push synchronization for mobile devices. Note: QNAP is not yet a supported platform by Zarafa. Try it at your own risk.

Warning: The build process is a bit complex. You should have some understanding of Linux and the command line. Although I did it with the TS-239 Pro-II model it should also work for other QNAP NAS models.

The description below is based on Zarafa 7.1.14 and QNAP firmware 3.8.4. I expect that the steps will also work for firmware 4.x versions (possibly with small changes), although I haven't tested it yet.

There are also QPKG community packages of Zarafa and Z-Push. Using the QPKG is a much easier and faster way to install Zarafa on a QNAP NAS. Actually the creator of the Zarafa QPKG (jdo2002) has used the information from this page when he originally created his package. At the time of writing the latest official version of this Zarafa QPKG is 0.6.2 which contains Zarafa 7.0.7 and Z-Push 1.5.10 (from 2011). There is also an experimental version 0.7.0 which contains Zarafa 7.1.7. More information on the Zarafa QPKG can be found here: http://wiki.qnap.com/wiki/Zarafa_Configuration, https://community.zarafa.com/pg/plugins/project/4338/developer/jdo/zarafa-for-qnap-nas, http://forum.qnap.com/viewtopic.php?f=265&t=51107, http://forum.qnap.com/viewtopic.php?f=265&t=86351.

If you want to use the Zarafa QPKG 0.7.0 with firmware 4.2.x you need to update the PHP MAPI extension. There is a section at the end of this page which describes how to do this.


The general build process is described at the Zarafa Wiki (http://www.zarafa.com/wiki/index.php/Compiling_source_code) for common Linux platforms. This guide can be followed also for QNAP, but some additional prerequisites are required.

Install ipkg tools

Optware has to be installed (Download: http://download.qnap.com/QPKG/Optware_0.99.163.zip). Check if the PATH variable contains /opt/bin at the beginning and the /opt/etc/init.d scripts are invoked. If not, see Install Optware IPKG on how to fix it. Make sure the following ipkg packages are installed

ipkg install bash binutils findutils sed perl patch pkgconfig coreutils zlib diffutils
ipkg install gcc bison flex libtool autoconf automake m4
ipkg install gettext openssl-dev libgsasl gnutls gnutls-dev
ipkg install python swig

Zarafa Sourcecode

Download the sourcecode of the Zarafa community version from http://community.zarafa.com (community version, release 7.1.14, all files including patches)


and unpack the files

mkdir /opt/tmp/zarafa
cd /opt/tmp/zarafa
tar xzf libical-0.44.tar.gz
tar xjf libvmime-0.9.2+svn603.tar.bz2
tar xzf zcp-7.1.14.tar.gz 

Compile and install Zarafa prerequisites

Apply patches and build libical

cd libical-0.44
cat ../libical-patches/*.diff |patch -p 1
./configure --prefix=/opt
make install

Apply patches and build libvmime (use -march=i686 to avoid a missing __sync_fetch_and_add_4 symbol, defining CFLAGS and CXXFLAGS didn't work)

cd ../libvmime-0.9.2
cat ../vmime-patches/*.diff |patch -p 1
./configure --prefix=/opt CC='gcc -march=i686' CXX='g++ -march=i686'
# had to remove a reference to /home/slug/.../libstdc++.la from /opt/lib/libstdc++.la
make install

I haven't built catdoc from sources, because it is available as an ipkg package

ipkg install catdoc 

Zarafa Installation

A number of preparational steps have to be done before Zarafa can be built. Some missing bits and header files have to be provided.

Gconv charsets

QNAP has only a limited number of character sets installed. They can be shown by the command iconv --list. The GNU gconv package provides additional character sets which are needed by Zarafa. Install gconv and link the gconv directory to the default location /usr/lib/gconv.

We use this script also to create a missing link /lib/uuid.so and a link in /usr/local/apache/modules to the Zarafa PHP-MAPI extension module.

ipkg install gconv-modules
cat <<EOF >/opt/etc/init.d/S05gconv-modules

# establish a symlink to missing glibc bits
if [ ! -L /usr/lib/gconv ]; then
test -d /usr/lib/gconv && mv /usr/lib/gconv /usr/lib/gconv-orig
ln -sf /opt/lib/gconv /usr/lib

# create missing link for uuid lib (for zarafa)
test -e /lib/libuuid.so || ln -sf /lib/libuuid.so.1 /lib/libuuid.so

# make mapi.so available in php (for zarafa)
if [ ! -e /usr/local/apache/modules/mapi.so ]; then
ln -sf /opt/lib/zarafa/mapi.so /usr/local/apache/modules/mapi.so
/etc/init.d/Qthttpd.sh restart

Test if all charsets are available (must output a very long list)

. /etc/profile
iconv --list
locale -a

PHP headers and php-config

To compile the Zarafa PHP-MAPI extension module, the PHP headers matching with the installed PHP version are needed. Determine the installed version and configuration options of the bundled PHP as follows

echo "<? phpinfo(); ?>" > /share/Web/phpinfo.php
/etc/init.d/Qthttpd.sh restart
http://nas/phpinfo.php    (replace "nas" by your NAS hostname)

Now download the PHP sourcecode for your installed version (PHP 5.3.26 for firmware 3.8.4, PHP 5.3.14 for firmware 3.7.2 to 3.8.3, PHP 5.3.28/29 for firmware 4.1.x, PHP 5.5.29 for firmware 4.2.0)

cd /opt/tmp/zarafa

# for PHP 5.3.26 (firmware 3.8.4)
wget http://museum.php.net/php5/php-5.3.26.tar.bz2
tar xjf php-5.3.26.tar.bz2
cd php-5.3.26

# for PHP 5.5.29 (firmware 4.2.0) this would be
#wget http://php.net/distributions/php-5.5.29.tar.bz2
#tar xjvf php-5.5.29.tar.bz2
#cd php-5.5.29

To recreate the headers for your environment, PHP must be configured similarly as it was done by QNAP. As PHP had been built for a particular version of the Apache Web server, the configuration requires access to the Apache apxs script. Patch /usr/local/apache/bin/apxs and /usr/local/apache/build/config_vars.mk to use local Optware tools

cd /usr/local/apache
cp build/config_vars.mk build/config_vars.mk-orig
cp bin/apxs bin/apxs-orig 

# adjust installdir
sed -i -e 's~/.*/apache_install_tmp~/usr/local/apache~' build/config_vars.mk bin/apxs

# adjust path to perl
sed -i -e 's~/opt/cross-project/.*/perl~/opt/bin/perl~' bin/apxs
cd -

Configure with the same options which had been used to build the bundled PHP version (some options for extension modules have been omitted)
This generates main/build-defs.h, main/php_config.h, scripts/php-config, etc.

./configure --prefix=/opt/tmp/zarafa/php5 --with-config-file-path=/etc/config/php.ini \
--with-config-file-scan-dir=/opt/etc/php.d --with-apxs2=/usr/local/apache/bin/apxs \
--enable-ftp --enable-sockets --enable-gd-native-ttf --enable-mbstring --with-libxml-dir=/opt \
--enable-sqlite-utf8 --enable-shared --enable-zend-multibyte --enable-exif --with-curlwrappers \
--with-pic=yes --enable-calendar --enable-bcmath

Install the PHP headers in a temporarly location, e.g. /opt/tmp/zarafa/php5.

make install-headers

# remove extra comma after the last entry in enum in zend.h (PHP 5.5.29)
sed -i -e  "s~FAILURE = -1,~FAILURE = -1~"  /opt/tmp/zarafa/php5/include/php/Zend/zend.h

# Prepare php-config script. 
chmod +x scripts/php-config

# Modify extension_dir to be /opt/lib/zarafa (PHP extension modules will be linked into
# /usr/local/apache/modules, which is recreated at each boot)
sed -i -e "s~extension_dir=.*~extension_dir='/opt/lib/zarafa'~" scripts/php-config

# test php-config script

C++ Boost Library headers

Zarafa uses the C++ boost library. A version of this library is already available on the QNAP NAS. Determine its version. Download and unpack the C++ boost headers for this version (boost 1.42.0 for firmware 3.8.4). The headers shall be linked into the default location during the build process

ls -l /usr/lib/libboost*
# http://www.boost.org/users/history/

cd /opt/tmp/zarafa
wget http://downloads.sourceforge.net/project/boost/boost/1.42.0/boost_1_42_0.tar.gz
tar xzf boost_1_42_0.tar.gz

# make boost headers available at system default location (/usr/include)
mkdir /usr/include
ln -s /opt/tmp/zarafa/boost_1_42_0/boost /usr/include


The getconf utility is missing on QNAP NAS. Create dummy getconf to use by the configure script

cd /opt/tmp/zarafa/zarafa-7.1.14
cat <<EOF >getconf
if [ "X\$1" = "XARG_MAX" ]; then
echo 32768
elif [ "X\$1" = "XLFS_CFLAGS" ]; then
echo "### getconf: unknown option: '$1' ###"
chmod +x getconf
export PATH=$PATH:`pwd`

Uuid lib and header

Provide a uuid.h header and save it as /opt/include/uuid/uuid.h. (The file can be found for example in GPL_TS/src/e2fsprogs-1.41.4/lib/uuid/uuid.h within the QNAP GPL sources (http://sourceforge.net/projects/qosgpl/), or you can copy it from some other Linux distribution)

ls -l /opt/include/uuid/uuid.h
ln -sf /lib/libuuid.so.1 /lib/libuuid.so

Build and install

Now the Zarafa package can be configured and built. We'll configure it for installation in /opt (similar to ipkg packages).

Set compiler flags and invoke configure (see also http://forums.zarafa.com/viewtopic.php?f=19&t=5595 for a rationale on some configure options). Replace the PHP version number by your version in the --with-php-config parameter of the configure command.

export CPPFLAGS='-I/opt/include/ncurses'

# build code only for the specified architecture to avoid an undefined reference to '__sync_fetch_and_add_4'
export CFLAGS='-O2 -march=i686'
export CXXFLAGS='-O2 -march=i686'

./configure --enable-release --prefix=/opt \
--with-userscript-prefix=/opt/etc/zarafa/userscripts \
--with-quotatemplate-prefix=/opt/etc/zarafa/quotamail \
--enable-unicode --with-mysql-config=/usr/local/mysql/bin/mysql_config \
--with-php-config=/opt/tmp/zarafa/php-5.3.26/scripts/php-config \
--with-xml2-config=/opt/bin/xml2-config \
--disable-kyotocabinet \
--enable-static-boost \

# the option no-vla is not available in gcc 4.2.1
sed -i -e 's~-Wno-vla~~' provider/soap/Makefile

# ECtools/zarafa-search runs into an error (unicode/coll.h not found)
# We don't need zarafa-search and therefore disable it in ECtools/Makefile
sed -i -e "s~zarafa-search~~" ECtools/Makefile

make install

this installs


Zarafa Configuration

See Zarafa Admin Manual (http://doc.zarafa.com/7.1/Administrator_Manual/en-US/html) and/or man pages

man zarafa
man zarafa-server
man zarafa-server.cfg
man zarafa-admin

Patch scripts

As we have installed zarafa in /opt, we need to patch a number of paths in scripts and configuration files.

The actual config files are located in /opt/etc/zarafa. Example config files are available in /opt/share/doc/zarafa/example-config. We adjust the paths by using the sed command to replace strings in files.

# adjust paths in init scripts
sed -i -e "s~/etc/zarafa~/opt/etc/zarafa~g" /opt/etc/init.d/zarafa-*
sed -i -e "s~/usr/bin/zarafa~/opt/bin/zarafa~g" /opt/etc/init.d/zarafa-*
sed -i -e "s~/etc/sysconfig/zarafa~/opt/etc/sysconfig/zarafa~g" /opt/etc/init.d/zarafa-*
sed -i -e "s~/etc/rc.d/init.d/functions~/opt/etc/init.d/functions~" /opt/etc/init.d/zarafa-*
sed -i -e "s~/bin/bash~/opt/bin/bash~" /opt/etc/init.d/zarafa-*

# adjust paths in config files
sed -i -e "s~/etc/zarafa~/opt/etc/zarafa~g" /opt/etc/zarafa/*.cfg
sed -i -e "s~/var/log/zarafa~/opt/var/log/zarafa~g" /opt/etc/zarafa/*.cfg /opt/etc/logrotate.d/zarafa
sed -i -e "s~/var/lib/zarafa~/opt/var/lib/zarafa~g" /opt/etc/zarafa/*.cfg

# add /opt/bin to PATH in userscripts
sed -i -e "s~PATH=/bin~PATH=/opt/bin:/opt/sbin:/bin~" /opt/etc/zarafa/userscripts/*.sh

# bash is available at /opt/bin/bash
sed -i -e "s~#\!/bin/bash~#\!/opt/bin/bash~" /opt/etc/zarafa/indexerscripts/*

# use /opt/etc/sysconfig/zarafa
sed -i -e "s~\${prefix}~/opt~" `grep -l prefix /opt/etc/zarafa/userscripts/*`

# create directory for logfiles
mkdir /opt/var/log/zarafa

# use killproc instead of /bin/kill to stop the server (otherwise daemon_mgr will restart it)
sed -i -e "s~/bin/kill \$ZARAFAPID.*~killproc \$SERVERPROGRAM~" /opt/etc/init.d/zarafa-server

The /opt/etc/init.d/functions file is used by the Zarafa init.d scripts. This file is available on RedHat and other Linux distributions but not on QNAP. Create the file /opt/etc/init.d/functions with the following contents:

# minimalistic init.d functions simulation (bash)
daemon() {
/sbin/daemon_mgr ${base} start "$* &"
killproc() {
if [ -n "$2" ]; then
/bin/kill ${2/SIG/} `pidof $base`
/sbin/daemon_mgr ${base} stop "$1"
status() {
return 0
success() {
echo "success: $*"
failure() {
echo "failure: $*"

Edit server configuration files

Now the Zarafa configuration files can be edited. Most default options already work. Check and adjust to your needs the options shown below:

Server configuration

# nano /opt/etc/zarafa/server.cfg
local_admin_users       = admin
log_method              = file
log_file                = /opt/var/log/zarafa/server.log
mysql_host              = localhost
mysql_port              = 3306
mysql_user              = root
mysql_password          = admin
mysql_database          = zarafa
plugin_path             = /opt/lib/zarafa
search-enabled          = no
attachment_storage      = database

chmod 600 /opt/etc/zarafa/server.cfg

Spooler configuration (sends outgoing e-mail)

# nano /opt/etc/zarafa/spooler.cfg
smtp_server     =       localhost
log_method      =       file
log_file        =       /opt/var/log/zarafa/spooler.log

Monitor configuration (sends quota warning emails)

# nano /opt/etc/zarafa/monitor.cfg
mailquota_resend_interval = 1
log_method      =       file
log_file        =       /opt/var/log/zarafa/monitor.log

POP3/IMAP gateway configuration (optional). (If the gateway shall not be used, then define "disabled_features=imap" in server.cfg)

# nano /opt/etc/zarafa/gateway.cfg
pop3_port       =       110
imap_port       =       143
log_method      =       file
log_file        =       /opt/var/log/zarafa/gateway.log

Ical gateway configuration (optional)

# nano /opt/etc/zarafa/ical.cfg
ical_port = 8008
log_method = file
log_file = /opt/var/log/zarafa/ical.log

Start the services

Make sure the following QNAP Servers are started

  1. Enable Web Server, Enable Secure Connection (SSL), port 8081
  2. Enable MySQL Server, Enable TCP/IP Networking, port 3306

Now the Zarafa servers can be started

/opt/etc/init.d/zarafa-server start
/opt/etc/init.d/zarafa-spooler start
/opt/etc/init.d/zarafa-monitor start
/opt/etc/init.d/zarafa-gateway start
/opt/etc/init.d/zarafa-ical start

Check the logfiles in /opt/var/log/zarafa. The first time the server is started, it creates the zarafa database schema in MySQL.

Optionally create links in /opt/etc/init.d for autostart

cd /opt/etc/init.d
ln -s zarafa-server S85zarafa-server
for f in zarafa-spooler zarafa-monitor zarafa-gateway zarafa-ical; do
ln -s $f S86$f

Create public store and users

Create public store

zarafa-admin -s

You may get the following error

terminate called after throwing an instance of 'std::runtime_error'
what():  locale::facet::_S_create_c_locale name not valid

This has happened to me when I tried to compile with the boost library version 1.46 from ipkg. A workaround is then to set LC_ALL=C. The zarafa-* executables are linked against the /opt/lib/libstdc++.so.6 library with an absolute path. The error does not happen if the executables were linked against /usr/lib/libstdc++.so.6. I haven't yet found an easy way to configure the build process so that it uses this library instead.

export LC_ALL=C
# see also https://svn.boost.org/trac/boost/ticket/5289

Now you can create users

zarafa-admin -c <username> -P -e <email> -f "<full name>"
zarafa-admin -l
zarafa-admin --details <username>

Install the Zarafa WebAccess PHP application

cp -r php-webclient-ajax /share/Web/webaccess
cp /share/Web/webaccess/config.php.dist /share/Web/webaccess/config.php

Configure include_path and TMP_PATH in /share/Web/webaccess/config.php

# nano /share/Web/webaccess/config.php

diff /share/Web/webaccess/config.php.dist /share/Web/webaccess/config.php
<       define("TMP_PATH", "/var/lib/zarafa-webaccess/tmp");
>       define("TMP_PATH", "/opt/var/lib/zarafa-webaccess/tmp");
<                        "/usr/share/php/");
>                        "/opt/share/php/");

The PHP web client writes output to debug.txt and errors.txt, so make these files writeable. Also create an upload directory.

touch /share/Web/webaccess/debug.txt /share/Web/webaccess/errors.txt
chmod 777 /share/Web/webaccess/debug.txt /share/Web/webaccess/errors.txt
mkdir -p /opt/var/lib/zarafa-webaccess/tmp
chmod 777 /opt/var/lib/zarafa-webaccess/tmp

The php.ini file has to be modified so that the Zarafa PHP-MAPI extension module is loaded. Add the row at the end of the [PHP] section.

# nano /etc/config/php.ini
extension = mapi.so

# restart apache to pick up php mapi module
/etc/init.d/Qthttpd.sh restart

You can check if the mapi extension module has been loaded by looking at: http://nas/phpinfo.php

The Zarafa WebAccess client application shall be available at the URL http://nas/webaccess

If there are problems, review the logfiles

# Apache Web Server log
tail -f /usr/local/apache/logs/error_log

# Zarafa Server log
tail -f /opt/var/log/zarafa/server.log

# Zarafa PHP Web Client debug and errors log
tail -f /share/Web/webaccess/debug.txt
tail -f /share/Web/webaccess/error.txt

Next Steps

Mail Server

You still need an SMTP server to be able to send emails out of Zarafa. An option would be to use postfix (recommended by Zarafa, see http://www.zarafa.com/wiki/index.php/MTA_integration) or QNAP XDove.


To enable SSL in the CalDAV/iCal and/or IMAP/POP3 servers you can follow these steps

# create an SSL private key and self signed certificate
openssl genrsa -out /opt/etc/zarafa/privkey.pem 2048
openssl req -new -x509 -key /opt/etc/zarafa/privkey.pem -out /opt/etc/zarafa/cert.pem -days 1095
chmod 600 /opt/etc/zarafa/privkey.pem

# Enable SSL for CalDAV/iCal
# nano /opt/etc/zarafa/ical.cfg
icals_enable = yes
icals_port = 8443
ssl_private_key_file = /opt/etc/zarafa/privkey.pem
ssl_certificate_file = /opt/etc/zarafa/cert.pem

# restart ical server
/opt/etc/init.d/zarafa-ical stop
/opt/etc/init.d/zarafa-ical start

# URL (without SSL): http://nas:8008/caldav
# URL (with SSL):    https://nas:8443/caldav
# see also http://doc.zarafa.com/7.1/Administrator_Manual/en-US/html/_configure_zarafa_caldav.html

# Enable SSL for POP3 and IMAP
# nano /opt/etc/zarafa/gateway.cfg
pop3s_enable    =       yes
pop3s_port      =       995
imaps_enable    =       yes
imaps_port      =       993
ssl_private_key_file    =       /opt/etc/zarafa/privkey.pem
ssl_certificate_file    =       /opt/etc/zarafa/cert.pem

# restart gateway server
/opt/etc/init.d/zarafa-gateway stop
/opt/etc/init.d/zarafa-gateway start


Z-Push ActiveSync (http://z-push.org) can be installed, if contacts, calendar items or emails shall be pushed to a mobile device. The Zarafa Administrator Manual contains a section on the installation of Z-Push (http://doc.zarafa.com/7.1/Administrator_Manual/en-US/html/_zpush.html). Quick installation notes:

wget http://download.z-push.org/final/2.2/z-push-2.2.4.tar.gz
tar xvzf z-push-2.2.4.tar.gz -C /share/Web
cd /share/Web
ln -s z-push-2.2.4 z-push

# create the state and log directories
cd /share/Web/z-push
mkdir state log
chown httpdusr state log

# redirect Microsoft-Server-ActiveSync to index.php
echo "Alias /Microsoft-Server-ActiveSync /share/Web/z-push/index.php" >>/usr/local/apache/conf/apache.conf

# adjust the following settings in the /share/Web/z-push/config.php file
define('TIMEZONE', 'Europe/Berlin');
define('STATE_DIR', '/share/Web/z-push/state/');
define('LOGFILEDIR', '/share/Web/z-push/log/');
define('BACKEND_PROVIDER', 'BackendZarafa');

# restart Apache
/etc/init.d/Qthttpd.sh restart

# test (use Zarafa credentials)

For the configuration of mobile clients see Zarafa User Manual (http://doc.zarafa.com/7.1/User_Manual/en-US/html/_configure_mobile_platforms.html).

Hint for Zarafa QPKG users with Firmware 4.2.x

If you have installed the Zarafa QPKG 0.7.0 on firmware 4.2.x and only want to update the PHP MAPI extension to make it work with PHP 5.5 you can build Zarafa ontop of the QPKG using the description below. In this case libraries and include files in /usr/local/zarafa which have been installed by the Zarafa QKPG will be used instead of libraries from Optware (note that we still have to use the build tools from Optware).

Note that this still does not work with MariaDB. To be able to use MariaDB you'll have to build a more recent Zarafa version (7.1.14 works). By following the steps below and install it ontop of the Zarafa QPKG all the other components provided by the QPKG package will still be leveraged. Just the zarafa-* executables and libraries will be replaced.

Prepare the PHP headers for your PHP version (PHP 5.5.29 for firmware 4.2.0):

wget http://php.net/distributions/php-5.5.29.tar.bz2
tar xjf php-5.5.29.tar.bz2
cd php-5.5.29

# make sure xml2-config is found during configuration
ln -s /usr/local/zarafa/bin/xml2-config /usr/local/bin

# LDFLAGS is set to make sure that system libs are linked first (otherwise configure may run into an error)
./configure --prefix=/opt/tmp/zarafa/php5 --with-config-file-path=/etc/config/php.ini \
--with-config-file-scan-dir=/opt/etc/php.d  --enable-ftp --enable-sockets --enable-gd-native-ttf \
--enable-mbstring --with-libxml-dir=/usr/local/zarafa/include/libxml2 \
--enable-shared --enable-exif --with-pic=yes --enable-calendar --enable-bcmath \
LDFLAGS='-L/lib -L/usr/lib -L/usr/local/zarafa/lib'

make install-headers

sed -i -e  "s~FAILURE = -1,~FAILURE = -1~"  /opt/tmp/zarafa/php5/include/php/Zend/zend.h

# patch php-config to link libraries from /usr/local/zarafa/lib instead of /opt/lib
# and set the default location for extensions to /opt/lib/zarafa
sed -e "s~-L/opt/lib~-L/usr/local/zarafa/lib~" \
    -e "s~extension_dir=.*~extension_dir='/opt/lib/zarafa'~" \
    <scripts/php-config >../php-config.tmp
chmod +x ../php-config.tmp

cd ..

Prepare the header files for the MariaDB/MySQL client library:

# MariaDB Connector/C sources (contains headers for libmysqlclient)
wget --no-check-certificate https://downloads.mariadb.org/interstitial/connector-c-2.2.0/mariadb-connector-c-2.2.0-src.tar.gz
tar xzf mariadb-connector-c-2.2.0-src.tar.gz

# remove extra comma at the end of an enum
sed -i -e 's~MYSQL_STATUS_QUIT_SENT,~MYSQL_STATUS_QUIT_SENT~' mariadb-connector-c-2.2.0-src/include/mysql.h

# disable getopt.h because it collides with a definition in the zarafa source
mv mariadb-connector-c-2.2.0-src/include/getopt.h mariadb-connector-c-2.2.0-src/include/getopt.h_disable

# create a dummy mysql_config script
cat >mysql_config.tmp <<EOF
case "\$1" in 
  --include) echo "-I/opt/tmp/zarafa/mariadb-connector-c-2.2.0-src/include";;
  --libs)    echo "-L/usr/local/mysql/lib -lmysqlclient";;
  --version) echo "unknown";;
chmod +x mysql_config.tmp

Then build Zarafa using the following configure options (The Zarafa QPKG must already be installed):

# use the same Zarafa version as in the QPKG if you only want to replace mapi.so
cd /opt/tmp/zarafa
tar xzf zcp-7.1.7.tar.gz
cd zarafa-7.1.7

# only more recent versions work with MariaDB, but then you have to replace all zarafa-* executables
#tar xzf zcp-7.1.14.tar.gz
#cd zarafa-7.1.14/

# build code only for the specified architecture to avoid an undefined reference to '__sync_fetch_and_add_4'
export CFLAGS='-O2 -march=i686'
export CXXFLAGS='-O2 -march=i686'

# make sure libraries from the Zarafa QPKG will be found
export PKG_CONFIG_PATH=/usr/local/zarafa/lib/pkgconfig

# make sure icu-config is found
export PATH=$PATH:/usr/local/zarafa/bin

# make sure /usr/local/zarafa/lib/python2.7 is used
sed -i -e "s~PYTHON_INCLUDES=.*~PYTHON_INCLUDES='-I/usr/local/zarafa/include/python2.7'~" \
    -i -e "s~PYTHON_LIBS=.*~PYTHON_LIBS='-L/usr/local/zarafa/lib -lpython2.7'~" \
    -i -e "s~PYTHON_LIBDIR=.*~PYTHON_LIBDIR='/usr/local/zarafa/lib/python2.7/site-packages'~" configure

# make sure /usr/local/zarafa/lib/ncurses5.so is used
sed -i -e "s~NCURSES_FLAGS=.*~NCURSES_FLAGS='-I/usr/local/zarafa/include/ncurses'~" \
    -i -e "s~NCURSES_LIBS=.*~NCURSES_LIBS='-L/usr/local/zarafa/lib -lncurses'~" configure

# configure Zarafa for installation in /usr/local/zarafa (as in the Zarafa QPKG)
./configure --enable-release --prefix=/usr/local/zarafa --enable-unicode \
--with-mysql-config=../mysql_config.tmp \
--with-php-config=../php-config.tmp \
--with-xml2-config=/usr/local/zarafa/bin/xml2-config \
CPPFLAGS='-I/usr/local/zarafa/include -I/usr/local/zarafa/include/libxml2' \
LDFLAGS='-L/lib -L/usr/lib -L/usr/local/zarafa/lib'


After the build has succeeded you can install everything (using make install) or just the PHP MAPI plugin. To install the MAPI plugin only and keep everything else from the QPKG unchanged requires that you use the same Zarafa version as in the QPKG (at the time of writing this is Zarafa 7.1.7 for Zarafa QPKG 0.7.0):

# install only the new PHP MAPI extension (temporary location /opt/lib/zarafa)
cd php-ext
make install
cd ..

# or install everything (if you use a different Zarafa version as in the QPKG)
# - all /usr/local/zarafa/bin/zarafa-* executables
# - libraries in /usr/local/zarafa/lib
# - the MAPI extension in /opt/lib/zarafa (temporary location)
#make install

# save the old PHP MAPI extension files
mv /usr/local/zarafa/phpmapi/mapi.so /usr/local/zarafa/phpmapi/mapi.so.orig
mv /usr/local/zarafa/phpmapi/mapi.la /usr/local/zarafa/phpmapi/mapi.la.orig
mv /usr/local/zarafa/share/php/mapi /usr/local/zarafa/share/php/mapi.orig

# copy the mapi extension to the right location
cp /opt/lib/zarafa/mapi.so /usr/local/zarafa/phpmapi/mapi.so
cp /opt/lib/zarafa/mapi.la /usr/local/zarafa/phpmapi/mapi.la

# check if all dependencies are resolved
ldd /usr/local/zarafa/phpmapi/mapi.so

# restart Apache
/etc/init.d/Qthttpd.sh restart

If you get an "Internal Server Error" when accessing the webaccess or webapp applications you need to remove the .htaccess files (They contain a configuration setting for magic quotes which is no longer supported in PHP 5.5)

rm /usr/local/zarafa/webaccess/.htaccess
rm /usr/local/zarafa/webapp/.htaccess

External Links & Resources

  • Zarafa Community (http://community.zarafa.com)
  • Zarafa Docs (http://doc.zarafa.com)
  • Z-Push (http://z-push.org)

-- Author: Max Böhm, 19.07.2011 (for Zarafa 7.0.0), 14.09.2013 (updated for Zarafa 7.1.5), 07.10.2015 (updated for Zarafa 7.1.14)