If you using the most recent versions of PHP and your project depends on MCrypt, you will get the error specific to Encrypt library which requires MCrypt extension. The main reason for missing MCrypt is that PHP no longer provides it by default and one must explicitly install it in order to continue using it.
Notes: This tutorial assumes that the most recent version of PHP is already installed on the system. You can also follow the tutorial How To Install PHP 7 On Ubuntu 18.04 LTS to install PHP on Ubuntu.
The newer version of this tutorial is available at - How To Install MCrypt For PHP 7 On Ubuntu 20.04 LTS.
Step 1: Install PHP Dev
Install the PHP development package using the below mentioned command.
sudo apt-get install php7.2-dev OR apt-get install php7.2-dev
Step 2: Install Build Tools
Install the build tools using the command mentioned below.
sudo apt-get -y install gcc make autoconf libc-dev pkg-config
Step 3: Install MCrypt Dev
Install the MCrypt development package using the below-mentioned command.
sudo apt-get -y install libmcrypt-dev
Step 4: Install MCrypt
Install the most recent version of MCrypt using the below-mentioned command.
#sudo pecl install mcrypt-1.0.1 sudo pecl install mcrypt-1.0.3
# Press enter on command prompt to complete installation libmcrypt prefix? [autodetect] :
Step 5: Configure PHP
Now configure the PHP by updating the php.ini file using the below-mentioned commands.
#sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/cli/conf.d/mcrypt.ini" #sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/apache2/conf.d/mcrypt.ini"
sudo bash -c "echo extension=/usr/lib/php/20190902/mcrypt.so > /etc/php/7.2/cli/conf.d/mcrypt.ini" sudo bash -c "echo extension=/usr/lib/php/20190902/mcrypt.so > /etc/php/7.2/apache2/conf.d/mcrypt.ini"
At last, test your installation.
php -i | grep "mcrypt"
These are the steps required to install the MCrypt extension on most recent versions of PHP including PHP 7.2, PHP 7.3.