Install Mcrypt for PHP 7 on CentOS 7

We support some legacy PHP code for several clients. Because of this, we have been strongly suggesting that they upgrade their code to PHP 7.3 so they can get off of older PHP 5.6 (and some even older – yikes!) servers.

In the process of doing this, we had a client who was using PHP’s mcrypt module to encrypt sensitive data. PHP 7.3 no longer natively supports mcrypt, but we needed to get the code wrapped up, because their budget at this time didn’t include switching the encryption package. So here’s what we did to get mcrypt working with PHP 7.3 on a CentOS 7 server. All these assume root privileges.

$ yum install php73w-devel gcc make autoconf libmcrypt libmcrypt-devel -y
$ cd /tmp
$ wget
$ tar xvf mcrypt-1.0.3.tgz
$ cd mcrypt-1.0.3
$ phpize
$ ./configure --with-php-config=/usr/bin/php-config
$ make
$ make install # add "extension=mcrypt" to php.ini file
$ apachectl -t
$ systemctl restart httpd
$ cd ..
$ rm -rf mcrypt-1.0.3*

Once done, their code was encrypting and decrypting data properly again! (Now we just need to get them to upgrade so we can remove mcrypt).

Does your PHP code need upgrading? We can help! Let us know what you need done and we would be happy to talk to you about it!

* Thanks to this post for the details.