Categories
HowTos Linux Troubleshootings

How to install mcrypt php extension on CentOS 6

Today a developer friend requested to trouble php mcrypt extension on his newly ordered VPS. Most of the time VPS by default comes up with very basic packages. For example, to build and add mcrypt php extension to existing php installation. You would required gcc, make, libtool, libmcrypt, libmcrypt-devel and may other packages.

mcrypt php extension necessary configuration & compilation : 

View current php version
php -v

Output :
PHP 5.3.3 (cli) (built: Jul 3 2012 16:53:21)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with the ionCube PHP Loader v4.0.14, Copyright (c) 2002-2011, by ionCube Ltd.

Downloading the same php version source code from php.net
cd /tmp/
wget http://museum.php.net/php5/php-5.3.3.tar.gz
tar -zxf php-5.3.3.tar.gz
cd php-5.3.3/ext/mcrypt

Prepare php extension to compile it.
phpize

Output :
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

aclocal
./configure
make
make install

You can can see mcrypt php extension is installed under php extensions directory:
ls /usr/lib64/php/modules/mcrypt.so

Enable mcrypt PHP extension in php.ini
echo "extension=mcrypt.so" >> /etc/php.d/mcrypt.ini

Verify mcrypt :
php -i | grep -i "mcrypt support"

Output:
mcrypt support => enabled

Known challenging and resolution :

phpize: command not found
yum install php-devel

configure.in:8: warning: LT_AC_PROG_SED is m4_require’d but not m4_defun’d
acinclude.m4:2636: PHP_CONFIG_NICE is expanded from…
configure.in:8: the top level

yum install libtool

………checking if debug is enabled… no
checking if zts is enabled… no
checking for re2c… no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk… gawk
checking for mcrypt support… yes, shared
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

yum install libmcrypt
wget ftp://rpmfind.net/linux/epel/6/x86_64/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
rpm -ivh libmcrypt-devel-2.5.8-9.el6.x86_64.rpm