Adding mcrypt Support to PHP on CoolStack 1.3.1

por | 6 diciembre, 2008

Antes instalar: pkg-get -i autoconf

Link: Adding mcrypt Support to PHP on CoolStack 1.3.1

One of the things that CoolStack is missing however is the mcrypt extension, which is used in a number of PHP applications, for example PHPMyAdmin. I was surprised this was missed out, as so many others are included. However it’s not too hard to add this ourself. This example is for CoolStack 1.3.1, but assuming the stack doesn’t change too much, the principles should be the same.

Compiling libmcrypt

Head on over to http://sourceforge.net/projects/mcrypt and download the latest libmcrypt source. You’ll need a healthy development environment, which I’m hoping to blog about in a future post (Hint: Grab Sun Studio 11 and put /opt/SUNWspro/bin at the front of your path).

You’ll want to choose a sensible place to install libmcrypt to – since I was producing a package for deployment to other servers, I chose “/opt/libs/libmcrypt”, but where you place this is up to you – “/opt/coolstack” is another suitable PREFIX path.

Let’s now compile and install libmcrypt (Using cc rather than gcc):

unset CC LDFLAGS CFLAGS
export CC=cc
./configure --prefix=/opt/libs/libmcrypt --enable-dynamic-loading \
 --with-included-algos=cast-128,gost,rijndael-128,twofish,arcfour,cast-256,loki97,rijndael-192,saferplus,wake,blowfish-compat,des,rijndael-256,serpent,xtea,blowfish,enigma,rc2,tripledes
make
make install

Et Voilà! You now have libmcrypt installed. If your compiler barfs, post a printout of what you get in the comments and I’ll assist if I can.

Compiling the php mcrypt extension

Assuming you have already downloaded, installed and configured CoolStack, all we need to do is fetch two CoolStack source packages. Nip on over to http://cooltools.sunsource.net/coolstack/, click the link to download, and choose “Source” as the Platform.

Download and install CSKruntime_1.3.1_Src.pkg.bz2 and CSKamp_1.3.1_Src.pkg.bz2 – this should place files under /opt/coolstack/src. Now lets compile the mcrypt extension:

cd /opt/coolstack/src/php5/
./prepare_src
cd php-5.2.6/ext/mcrypt
/opt/coolstack/php5/bin/phpize
./configure --with-php-config=/opt/coolstack/php5/bin/php-config \
--with-mcrypt=/opt/libs/libmcrypt/
make
make install

You can check to make sure the resulting mcrypt.so file is safe to use by doing:

ldd /opt/coolstack/php5/lib/php/extensions/no-debug-non-zts-20060613/mcrypt.so

This should not show any “(file not found)” errors.

Finally, add extension=mcrypt.so to /opt/coolstack/php5/lib/php.ini. Restart Apache (svcadm restart http) – phpinfo(); in a php file should now show a happy mcrypt installation 🙂