This tutorial shows you how to install libmcrypt and the companion PHP module under RedHat Linux 6 and Oracle Linux 6.
By default, RHEL and OL do not provide mcrypt or libmcrypt packages for the 6.x release. Subsequently, they don’t provide PHP5 mcrypt modules either. Many PHP apps including PHPMyAdmin and Magento make use of the better crypto support of libmcrypt.
So how do you install it? You have to build it.
Part 1: Building libmcrypt
Part 1, Step 1: Install your build environment
libmcrypt is written in C++ so you need a C++ compiler.
sudo yum install gcc-c++.x86_64
That will install the compiler and dependencies.
Part 1, Step 2: Get the software
Download it here: http://sourceforge.net/projects/mcrypt/files/
Remember, download libmcrypt, not mcrypt.
Part 1, Step 3: Pick a location and unpack it
Most people install software in to the default location, but I’m going to install in to somewhere that isn’t owned by root just to illustrate how to separate your custom app components from the OS.
mkdir /myappserver
cd /myappserver
cp /path/to/download/libmcrypt-2.5.8.tar.bz2 /myappserver/
bunzip2 libmcrypt-2.5.8.tar.bz2
tar xf libmcrypt-2.5.8.tar
mv libmcrypt-2.5.8 libmcrypt-install
Part 1, Step 4: Build it!
cd libmcrypt-install
./configure --prefix=/myappserver/libmcrypt-2.5.8 --exec-prefix=/myappserver/libmcrypt-2.5.8 --disable-posix-threads
make
make install
Part 1, Step 4: Make a Symlink
In order to make life easier for upgrades later, symlink libmcrypt to the version you built. This will let you compile a new version later and simply move the symlink. Anything else you build against this package will only need to know about the symlink.
ln -s /myappserver/libmcrypt-2.5.8/ /myappserver/libmcrypt
You have successfully installed libmcrypt. You can move it from server to server by simply copying /myappserver/libmcrypt-2.5.8/ to any other machine.
Part 2: Building the PHP Module
Building the PHP module can be done in one of two ways.
- Build your own PHP and copy the module to an existing PHP installation
- Build your own PHP and use it
I’m not going to do a full tutorial on building PHP here (Option 2). Just note that the steps are the same as Option 1, but instead of copying the extention in to your PHP installation, compile PHP with all the modules you need, then install and use the PHP you built.
Option 1: Build your own PHP and copy the module to an existing PHP installation
Part 2, Option 1, Step 1: Install your build environment
PHP is written in C so you need a C compiler.
sudo yum install gcc.x86_64
That should give you everything you need to compile PHP.
Part 2, Option 1, Step 2: Get the software
MAKE SURE YOU DOWNLOAD THE PHP VERSION THAT MATCHES YOUR INSTALLATION
Download it here: http://us3.php.net/downloads.php
For this tutorial, I used PHP 5.5.13
Part 2, Option 1, Step 3: Pick a location and unpack it
I’m going to use a non-standard location since I’m just building the software. I’m not going to use it from here.
mkdir /myappserver
cd /myappserver
cp /path/to/download/php-5.5.13.tar.bz2 /myappserver/
bunzip2 php-5.5.13.tar.bz2
tar xf php-5.5.13.tar
cd php-5.5.13
Part 2, Option 1, Step 4: Build it!
./configure --prefix=/myappserver/php-5.5.13 --exec-prefix=/myappserver/php-5.5.13 --with-mcrypt=/myappserver/libmcrypt
make
Note the --with-mcrypt=/myappserver/libmcrypt
option. This points to the symlink above. If you need to upgrade libmcrypt later or rebuild the module for any reason, you don’t need to worry about what version of libmcrypt you have, just use the symlink!
You should now be able to find your module in /myappserver/php-5.5.13/ext/mcrypt
Part 2, Option 1, Step 5: Use it!
- Copy the
mcrypt
directory above in to theext
directory in your PHP installation. - Restart your Apache server
Test it with a little PHP code:
<?php
extension_loaded('mcrypt') ? print 'Mcrypt is working' : print 'Mcrypt is not working';
?>
Did you find this post useful or have questions or comments? Please let me know!
It is interesting that the PHP manual says to use –disable-posix-threads, even though the help page from doing a ./configure –help does not list that as an option.