How to install PHP Mcrypt extension on Ubuntu 20.04 or Debian

What is the PHP Mcrypt extension?

PHP Mcrypt extension provides encryption facilities to web applications that need the functionality of modern algorithms such as AES. This extension works as an interface to the Mcrypt’s libmcrypt library which implements all the algorithms and modes found in it such as DES, TripleDES, Blowfish (default), SAFER-SK128, LOKI97, GOST, RC2, RC6, MARS, IDEA, RIJNDAEL-128 (AES), RIJNDAEL-192, TWOFISH, TEA, RC2, and more. However, PHP developers have removed it from the PHP package bundle since the launch of php7.2 because of no further development in Mcrypt, thus the extension also gets decrypted. Sodium (available as of PHP 7.2.0) and OpenSSL are now some alternatives to it.

However, the PHP Mcrypt extension has been moved to the PECL repository, thus if somebody wants, he or she can install it on Ubuntu 20.04 LTS using Pear. Here we will show how?

Open Command terminal and run system update

Go to Terminal, if you are using CLI server then you are already there. Simply run the system update command to refresh the repo cache and update the installed packages of the system.

sudo apt update

Install Developer tools & Dependencies

To install PHP Mcrypt on Ubuntu 20.04 or Debian, we have to install some tools needed to build packages from the source along with some developer dependency packages.

sudo apt install gcc make autoconf libc-dev pkg-config libmcrypt-dev php-pear php-dev

 

Channel-update for PEAR and PECL

The below two commands will update the channels that allow Pear and Pecl to fetch packages-

pecl channel-update pecl.php.net
pecl update-channels

 

Install Php Mcrypt extension on Ubuntu 20.04 or Debian

Finally, use the Pecl command to download and install php-mcrypt extension on your system

pecl install mcrypt

 

Enable “extension=mcrypt.so” via php.ini

Once the installation is complete to activate the extension we have to add it in the php.ini file of the system. For that simply edit the php.ini file and under Dynamic extension, type: extension=mcrypt.so beside other extensions, as shown in the screenshot.

sudo nano /etc/php/*/apache2/php.ini

Save the file ctrl+X, type Y, and hit the Enter key.

Install php Mcrypt Extension on Ubuntu 20.04

 

Restart Apache

To ensure your web server has successfully recognized the enabled PHP mcrypt extension, reload the Apache server-

sudo systemctyl reload apache2

 

Confirm Mcrypt is enabled

Run:

php -m | grep mcrypt

The output will be-

mcrypt

 

Other Tutorials-

 

One Response

  1. Alex July 16, 2021

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.