As mentioned in our previous article PHP 7.2 or PHP 7.3 with mcrypt – manual build the PHP versions 7.2 and 7.3 do not include PHP mcrypt module. The mcrypt module was part of PHP 5 till 7.1, in which it was deprecated and removed in 7.2.
In this article we show how to build mcrypt module for Ubuntu based on our previous article showed above. Because of the great popularity of Ubuntu and it has no PHP mcrypt package in Ubuntu package system unlike other Linux distributions (like Gentoo, which created a package) we decided to make this article.
For our purpose we use Ubuntu 18.04.2 LTS and here is what the steps to have the mcrypt PHP module:
STEP 1) Update and install mcrypt library and header development packet
sudo apt update -y sudo apt install -y libmcrypt-dev
STEP 2) Install the GNU GCC build utility and the PHP dev packet
This is the compiler to build the module.
sudo apt install -y build-essential sudo apt install -y php7.2-dev
STEP 3) Download the PHP mcrypt module and build it.
cd mkdir mcrypt-php-module-manual cd mcrypt-php-module-manual wget https://pecl.php.net/get/mcrypt-1.0.2.tgz tar xzf mcrypt-1.0.2.tgz cd mcrypt-1.0.2 phpize aclocal libtoolize --force autoheader autoconf ./configure make sudo make install
STEP 4) Load the module in the PHP configuration (we use PHP-FPM and PHP-CLI) and block future PHP versions to be installed when apt update is used.
Because we compile the PHP mcrypt module for the specific currently installed PHP we do not want to upgrade our PHP when there is an update and the mcrypt module to fail to load. Each change of the PHP version (upgrade) would require a recompile against the current PHP version. To see more for holding and unholding Ubuntu packages – apt-mark – upgrade with the exception of certain packages Of course, if there is an update for PHP you must install it just recompile the mcrypt package, too!
echo "extension=mcrypt.so" > 20-mcrypt.ini sudo cp 20-mcrypt.ini /etc/php/7.2/cli/conf.d/20-mcrypt.ini sudo cp 20-mcrypt.ini /etc/php/7.2/fpm/conf.d/20-mcrypt.ini sudo apt-mark hold php-cli php7.2-cli php-fpm php7.2-fpm