Zarafa Installation On QNAP

From QNAPedia
Revision as of 15:16, 9 October 2015 by Mjb (talk | contribs)
Jump to navigation Jump to search

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.



Overview

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.0 and 4.1 versions (possibly with small changes), although I haven't tested it. It is currently unknown if this will also work for the new firmware 4.2 as in this version several components have been updated to newer version, for example PHP 5.3 to PHP 5.5.

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 QPKG is Zarafa 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.

Prerequisites

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. Check if the PATH variable contains /opt/bin 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)

(catdoc-0.94.2.tar.gz)
libical-0.44.tar.gz
libical-patches/*
libvmime-0.9.2+svn603.tar.bz2
vmime-patches/*
zcp-7.1.14.tar.gz

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
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'
make
# 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
#!/bin/sh

# 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
fi

# 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
fi
EOF

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

/opt/etc/init.d/S05gconv-modules
. /etc/profile
iconv --list
locale -a
locale

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
/usr/local/apache/bin/apachectl -k 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
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

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/x86/sys-root/usr/bin/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

# 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
scripts/php-config

C++ Boost Library headers

Zarafa uses the C++ boost library. A version of this library is already available on the QNAP TS. 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

Getconf

The getconf utility is missing on QNAP TS. 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
else
echo "### getconf: unknown option: '$1' ###"
fi
EOF
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)

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/quotamails \
--enable-unicode --with-mysql-config=/usr/local/mysql/bin/mysql_config \
--with-php-config=/opt/tmp/zarafa/php-5.3.26/scripts/php-config \
--disable-kyotocabinet \
--enable-static-boost

make
make install
# the option no-vla is not available in gcc 4.2.1
sed -i -e 's~-Wno-vla~~' provider/soap/Makefile
# /opt/include/libxml2 has to be added to the include path in inetmapi/Makefile
# (so that libxml/HTMLparser.h is found)
sed -i -e "s~DEFAULT_INCLUDES = -I.*~& -I/opt/include/libxml2~" inetmapi/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

this installs

/opt/lib/zarafa
/opt/bin/zarafa-*
/opt/share/doc/zarafa
/opt/share/doc/zarafa/example-config
/opt/etc/init.d/zarafa-*
/opt/etc/logrotate.d/zarafa
/opt/etc/php.d/zarafa.ini
/opt/etc/sysconfig/zarafa
/opt/etc/zarafa/*.cfg
/opt/etc/zarafa/userscripts

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() {
base=${1##*/}
/sbin/daemon_mgr ${base} start "$* &"
}
killproc() {
base=${1##*/}
if [ -n "$2" ]; then
/bin/kill ${2/SIG/} `pidof $base`
fi
/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
done

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
49c49
<       define("TMP_PATH", "/var/lib/zarafa-webaccess/tmp");
---
>       define("TMP_PATH", "/opt/var/lib/zarafa-webaccess/tmp");
54c54
<                        "/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_dir = /opt/lib/zarafa
extension = mapi.so

# restart apache to pick up php mapi module
/usr/local/apache/bin/apachectl -k 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.

SSL

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

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
/usr/local/apache/bin/apachectl -k restart

# test (use Zarafa credentials)
http://nas/Microsoft-Server-ActiveSync

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).


-- 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)