I found out that when I wanted to use postfixadmin, roundcube webmail and phpmyadmin, it asked for the libmcrypt module. So here is how I added mcrypt to PHP:

First download the libmcrypt sourcecode. Don’t download the regular mcrypt package!

First you need to unpack the source code and decide if you need the 32 bits or 64 bits version (of your apache/php installation).

for 64 bits systems use:

CFLAGS="-arch x86_64" \
CXXFLAGS="-arch x86_64" \
./configure --disable-posix-threads

for 32 bits systems use:

./configure --disable-posix-threads

For all versions use:

sudo make install

To compile and install the library.

Next step is to recompile the php installation as described on this page:
Compiling PHP in 64 bits or Compiling PHP in 32 bits depending on your requirements.

The only change you need to make is to add:

--with-mcrypt \

To the configure statement and it will include this library for you.

For example when compiling in 32 bits use:

./configure --prefix=/usr/local/php5 \
  --mandir=/usr/share/man \
  --infodir=/usr/share/info \
  --sysconfdir=/etc \
  --with-config-file-path=/etc \
  --with-zlib \
  --with-zlib-dir=/usr \
  --with-openssl \
  --without-iconv \
  --enable-exif \
  --enable-ftp \
  --enable-mbstring \
  --enable-mbregex \
  --enable-sockets \
  --with-mysql=mysqlnd \
  --with-pdo-mysql=mysqlnd \
  --with-mysqli=mysqlnd \
  --with-mcrypt \