Wednesday, September 5, 2018

Howto install mcrypt for PHP 7.2

PHP extensions have always utilised reuse of applications to provide extra functionality to developers. One such is the use of mycrypt. As of PHP 7.1, the mcrypt is deprecated and totally removed in PHP 7.2. Unfortunately for those with application that rely on mcrypt, this means the end of the road. In my case, development of a Laravel application had dependencies on mcrypt when doing an update with the command;

$ composer update

The mcrypt is a replacement of Unix/Linux crypt( ) that encrypt files. The PHP extension is php-mcrypt, and this is used to interface between PHP application and the mcrypt utility.

However, there is a solution that use mcrypt found in the PHP Extension Community Library (PECL). In this example, its tested on

CentOS 7.5 
Apache 2.4.6 (CentOS)
PHP 7.2.5 (sp.repo.webtatic.com)

Step 1. Install mcrypt utility.

$ pecl search mcrypt
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
Retrieving data...0%
.Matched packages, channel pecl.php.net:
=======================================
Package       Stable/(Latest)  Local
mcrypt        1.0.1 (snapshot)       Bindings for the libmcrypt library
mcrypt_filter 0.1.0 (beta)           Applies mcrypt symmetric encryption using stream filters



Install mcrypt and its development library then update the pecl.

$ sudo pecl channel-update pecl.php.net
$ sudo yum install libmcrypt
$ sudo yum install libmcrypt-devel


Step 2. Install php-devel (or php72w-devel if you use webtatic repo)

$ sudo yum install php72w-devel


Step 3. Install mcrypt extension

Either specify specifically a channel or use default
$ sudo /usr/bin/pecl install channel://pecl.php.net/mcrypt-1.0.1
or
$ sudo /usr/bin/pecl install mcrypt-1.0.1

Create the file /etc/php.d/mcrypt.ini with the contents
; Enable mcrypt extension module from pecl
extension=mcrypt.so


Restart Web server.

Note: If for some strange reason php still doesn't detect mcrypt extension, I would give a reboot.

Done.

No comments:

Blog Archive