I had to install mcrypt on a new virtual private server running CentOS 5.3 and Plesk 9.2. We didn’t want to do compile it, so we used yum to install it. The libmcrypt library is used to provide cryptographic functions and we are planning to use them in our php scripts. Let’s try to install it…

[root@nechi etc]# cat /etc/redhat-release
CentOS release 5.3 (Final)
[root@nechi etc]# uname -a
Linux nechi.local 2.6.18-028stab064.7 #1 SMP Wed Aug 26 13:11:07 MSD 2009 x86_64 x86_64 x86_64 GNU/Linux
[root@nechi etc]# php -v
PHP 5.2.11 (cli) (built: Oct 7 2009 08:45:24)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
[root@nechi etc]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* atomic: www5.atomicorp.com
* base: mirror.nic.uoregon.edu
* updates: mirror.chpc.utah.edu
* addons: centos.mirror.nac.net
* extras: mirror.stanford.edu
plesk | 951 B 00:00
atomic | 951 B 00:00
base | 2.1 kB 00:00
updates | 1.9 kB 00:00
addons | 951 B 00:00
extras | 1.1 kB 00:00
repo id repo name status
addons CentOS-5 - Addons enabled : 0
atomic CentOS / Red Hat Enterprise Linux 5 - at enabled : 709
base CentOS-5 - Base enabled : 3,348
extras CentOS-5 - Extras enabled : 290
plesk Plesk Server Administrator enabled : 193
updates CentOS-5 - Updates enabled : 363
repolist: 4,903
[root@nechi etc]#

The easiest way to do this is to use the php-mcrypt rpm package. That package has some dependencies. Earlier, I had installed libmcrypt so I figured I could just install the php-related rpm and I’d be done:

[root@nechi etc]# yum install php-mcrypt
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* atomic: www5.atomicorp.com
* base: mirror.nic.uoregon.edu
* updates: mirror.chpc.utah.edu
* addons: centos.mirror.nac.net
* extras: mirror.stanford.edu
Excluding Packages from Plesk Server Administrator
Finished
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package php-mcrypt.x86_64 0:5.2.11-2.el5.art set to be updated
--> Processing Dependency: libltdl.so.3()(64bit) for package: php-mcrypt
---> Package php-mcrypt.i386 0:5.2.11-2.el5.art set to be updated
--> Processing Dependency: libltdl.so.3 for package: php-mcrypt
--> Processing Dependency: libc.so.6(GLIBC_2.4) for package: php-mcrypt
--> Processing Dependency: libc.so.6 for package: php-mcrypt
--> Processing Dependency: libmcrypt.so.4 for package: php-mcrypt
--> Processing Dependency: libc.so.6(GLIBC_2.1.3) for package: php-mcrypt
--> Processing Dependency: libc.so.6(GLIBC_2.0) for package: php-mcrypt
--> Running transaction check
---> Package libtool-ltdl.i386 0:1.5.22-6.1 set to be updated
---> Package php-mcrypt.i386 0:5.2.11-2.el5.art set to be updated
--> Processing Dependency: libmcrypt.so.4 for package: php-mcrypt
---> Package glibc.i686 0:2.5-42 set to be updated
---> Package libtool-ltdl.x86_64 0:1.5.22-6.1 set to be updated
--> Finished Dependency Resolution
php-mcrypt-5.2.11-2.el5.art.i386 from atomic has depsolving problems
--> Missing Dependency: libmcrypt.so.4 is needed by package php-mcrypt-5.2.11-2.el5.art.i386 (atomic)
Error: Missing Dependency: libmcrypt.so.4 is needed by package php-mcrypt-5.2.11-2.el5.art.i386 (atomic)
[root@nechi etc]#

Oh great, it’s 1am on a Saturday night and my new OS hates me (digression: this speaks volumes).

[root@nechi etc]# yum list installed | grep mcrypt
libmcrypt.x86_64 2.5.8-4.el5.centos installed
[root@nechi etc]# ldconfig -p | grep libmcrypt.so.4
libmcrypt.so.4 (libc6,x86-64) => /usr/lib64/libmcrypt.so.4
[root@nechi etc]# find / -name libmcrypt.so.4
/usr/lib64/libmcrypt.so.4
[root@nechi etc]# ls -la /usr/lib64/libmcrypt.so.4
lrwxrwxrwx 1 root root 18 Dec 6 00:25 /usr/lib64/libmcrypt.so.4 -> libmcrypt.so.4.4.8
[root@nechi etc]# yum install libmcrypt-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* atomic: www5.atomicorp.com
* base: mirror.nic.uoregon.edu
* updates: mirror.chpc.utah.edu
* addons: centos.mirror.nac.net
* extras: mirror.stanford.edu
Excluding Packages from Plesk Server Administrator
Finished
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package libmcrypt-devel.x86_64 0:2.5.8-4.el5.centos set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================================
Installing:
libmcrypt-devel x86_64 2.5.8-4.el5.centos extras 10 k

Transaction Summary
=========================================================================================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 10 k
Is this ok [y/N]: y
Downloading Packages:
libmcrypt-devel-2.5.8-4.el5.centos.x86_64.rpm | 10 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : libmcrypt-devel [1/1]

Installed: libmcrypt-devel.x86_64 0:2.5.8-4.el5.centos
Complete!
[root@nechi etc]# yum install php-mcrypt

So can you guess what happened next? The library was found the next time I tried to install it, right? Of course not. It still couldn’t find the stupid library. So Google and I had a talk and it turns out that you need to be really specific about your package (a good general rule in most situations) if you have a 64-bit machine.

[root@nechi etc]# yum install php-mcrypt.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* atomic: www5.atomicorp.com
* base: mirror.nic.uoregon.edu
* updates: mirror.chpc.utah.edu
* addons: centos.mirror.nac.net
* extras: mirror.stanford.edu
Excluding Packages from Plesk Server Administrator
Finished
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package php-mcrypt.x86_64 0:5.2.11-2.el5.art set to be updated
--> Processing Dependency: libltdl.so.3()(64bit) for package: php-mcrypt
--> Running transaction check
---> Package libtool-ltdl.x86_64 0:1.5.22-6.1 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================================
Installing:
php-mcrypt x86_64 5.2.11-2.el5.art atomic 27 k
Installing for dependencies:
libtool-ltdl x86_64 1.5.22-6.1 base 37 k

Transaction Summary
=========================================================================================================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 64 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): php-mcrypt-5.2.11-2.el5.art.x86_64.rpm | 27 kB 00:00
(2/2): libtool-ltdl-1.5.22-6.1.x86_64.rpm | 37 kB 00:00
-----------------------------------------------------------------------------------------------------------------------------------------
Total 76 kB/s | 64 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : libtool-ltdl [1/2]
Installing : php-mcrypt [2/2]

Installed: php-mcrypt.x86_64 0:5.2.11-2.el5.art
Dependency Installed: libtool-ltdl.x86_64 0:1.5.22-6.1
Complete!
[root@nechi etc]#

OMFG. Hey, did I mention that it is a Saturday night?

[root@nechi etc]# php -r "echo phpinfo();" | grep "^mcrypt"
mcrypt
mcrypt support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value
[root@nechi etc]#