How to install mailpiler on CentOS 5.x

Mailpiler project is available on the project’s page:

This is a quick instruction set to install mailpiler on CentOS 5.x 64 bit machine. After installing the default system you should always update your packages with yum update. I will use two extended repository, the EPEL and the IUS. I think everybody knows the EPEL, but I found IUS really convenient to install php5.x, particularly for suhosin-patch and mysql5.x.

So, let’s start with installing these packages:

cd /tmp
rpm -ivh epel-release-5-4.noarch.rpm
rpm -ivh ius-release-1.0-10.ius.el5.noarch.rpm
rpm --import /etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY

When it is done, we can start to build our http and SQL server, set the daemons startup and secure the mysql installation:

yum install httpd mysql51-server mysql51
chkconfig --levels 235 mysqld on
chkconfig --levels 235 https on
service httpd start
service mysqld start

The LAMP stack will be complete with php. I used the packages from IUS repository, because they take care about the name collision, since they introduced their naming convention in terms of package names.

yum install php53u-common php53u-mysql php53u-ldap php53u-gd php53u-devel php53u-pdo php53u php53u-odbc php53u-xml php53u-xmlrpc php53u-bcmath php53u-snmp php53u-soap php53u-pear php53u-cli php53u-imap php53u-dba php53u-mbstring php53u-suhosin

We need these compiling and development libraries also:

yum install gcc openssl-devel memcached libjpeg-devel libpng-devel gcc-c++ pkgconfig fontconfig-devel latex2rtf php53u-pecl-memcache mysql51-devel zlib-devel latex2html

Our basic system is ready, let’s start to install the components for mailpiler:

Sphinx is the search engine for the mails, and we are lucky, it is available from an rpm package:

cd /tmp
rpm -i ./sphinx-2.0.5-1.rhel5.x86_64.rpm

Let’s get our hands dirty, download and compile the other components…
Libzip for zip file handling:

cd /tmp
tar -xvzf ./libzip-0.10.1.tar.gz
cd libzip-0.10.1
make install

If you have the following error:
configure: error: ZLIB version too old, please install at least v1.1.2
zlib-devel is missing, just do yum install zlib-devel.

Since these components will use their own library, you should add the /usr/local/lib to your

echo /usr/local/lib > /etc/
ldconfig; ldconfig -p | grep libzip

You should see two lines, with libzip libraries at the end of the command.

Install catdoc:

cd /tmp
tar -xvzf ./catdoc-0.94.2.tar.gz
cd catdoc-0.94.2
make install

Install poppler (formerly known as pdf2text):

cd /tmp
tar xvzf poppler-0.20.5.tar.gz
cd poppler-0.20.5

The output should be like that:

Building poppler with support for:
  font configuration: fontconfig
  splash output:      yes
  cairo output:       no (requires cairo >= 1.10.0)
  qt4 wrapper:        no
  glib wrapper:       no (requires cairo output)
    introspection:    no
  cpp wrapper:        yes
  use gtk-doc:        no
  use libjpeg:        yes
  use libpng:         yes
  use libtiff:        no
  use zlib:           no
  use libcurl:        no
  use libopenjpeg:    no
  use cms:            no
  command line utils: yes

Then compile it:

make install 
make check

Install unrtf:

cd /tmp
tar xvzf unrtf-0.21.2.tar.gz
cd  unrtf-0.21.2
make install
make check

You will need tre, but not from the repositories:

cd /tmp
tar -xvzf tre-0.8.0.tar.gz
cd tre-0.8.0
make install
make check

Last step before the showtime: copy zipconf.h to the directory where piler will look for it:

 cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/

Start Piler install

groupadd piler
useradd -g piler -s /bin/sh -d /var/piler piler
usermod -L piler
cd /tmp
tar -xvzf piler-0.1.21.tar.gz 
cd piler-0.1.21
./configure --enable-memcached --localstatedir=[where you want to store your emails]

If you have the following error:

/ undefined reference to `tre_regexec'
./ undefined reference to `tre_regcomp'
./ undefined reference to `tre_regfree'
collect2: ld returned 1 exit status

Remove the tre-devel package (yum remove tre-devel), and run configure again.
Let’s put piler together:

su -c 'make install'

After successful compile run ldconfig to import piler libraries and set up the config files for piler:

nano /usr/local/etc/piler.conf
### Change the following lines according to your configuration: mydomains=yourdomain mysqlsocket=/var/lib/mysql/mysql.sock

Remove sendmail to not block your port 25:

yum remove sendmail

Create a key for the email store encryption, from piler directory (/tmp/piler-0.1.21):

make key
cp piler.key /usr/local/etc
chgrp piler /usr/local/etc/piler.key
chmod 640 /usr/local/etc/piler.key

IMPORTANT! Make sure you never lose/overwrite the key otherwise you won’t access your archive ever again. So whenever you upgrade be sure to keep your existing key file.

Create a database for piler, it is highly recommended that not use verystrongpassword!

#mysql -u root -p
mysql>create database piler character set 'utf8';
mysql>grant all privileges on piler.* to [email protected] identified by 'verystrongpassword';
mysql>flush privileges;

Import piler initial database:

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

Sphinx setup:
mv /etc/sphinx/sphinx.conf /etc/sphinx/sphinx.conf.orig
cp etc/sphinx.conf /etc/sphinx
nano /etc/sphinx/sphinx.conf
## Change sql_pass parameters (it is piler in default) according to you system.

Start firs indexing:
#su - piler
$indexer --all

Start piler:

sh init.d/rc.piler start

If you have an error: piler: error while loading shared libraries: cannot open shared object file: No such file or directory, then check your /etc/ file, and run ldconfig again.

Start sphinx:

nano init.d/rc.searchd
## Change the line (line 10):
        su piler -c '/usr/local/bin/searchd'                                                                                                                                                
##to this
        su piler -c '/usr/bin/searchd'                                                                                                                                                 
sh init.d/rc.searchd start

Copy files to the web server’s DocumentRoot:

mv webui /var/www/html/piler

Set up cron jobs

For piler user:
# if you use different version of sysstat (mpstat) then perhaps the 10th variable contains the %idle number
*/5 * * * * LC_ALL=C mpstat | tail -1 | awk '{print $11}' > /var/piler/stat/cpu.stat
*/15 * * * * /usr/local/bin/indexer --quiet delta1 --rotate && sleep 2 && /usr/local/bin/indexer --quiet --merge main1 delta1 --merge-dst-range deleted 0 0 --rotate
*/15 * * * * /usr/local/bin/indexer --quiet tag1 --rotate
*/15 * * * * /usr/local/bin/indexer --quiet note1 --rotate
30 7 * * * /usr/local/libexec/piler/daily-report.php /var/www/html/piler

Set up Apache:

Add the following lines to the /etc/httpd/conf/httpd.conf:

<VirtualHost *>
ServerName mailarchive.[yourdomain]
DocumentRoot /var/www/html/piler
<Directory /var/www/html/piler>
AllowOverride All
ServerAdmin [email protected][yourdomain]
ErrorLog /var/log/httpd/mailarchive.[yourdomain]-error_log
CustomLog /var/log/httpd/mailarchive.[yourdomain]-access_log common

Edit the /var/www/html/piler/config.php.
The most important values that you have to change:

DIR_BASE ## Don'r t forget the ending slash / ##

Restart apache:

service httpd restart

We are done! You can login on your with [email protected]/pilerrocks…
Nice and easy, right? 😉

The last thing to drop a copy from every mail from your primary mail server to this system, so it is better to create a subdomain for this in the DNS and then bcc or log everything to this particular server.

You can import mails from existing mailboxes/IMAP servers with pilerimport.

5 thoughts on “How to install mailpiler on CentOS 5.x

  1. can u plz tell me how to install this mail piler in redhat linux 6 with complete commands to install and configure ,and what all need to be installed to install mail piler? where can i download this mail piler for free

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.