Explains the steps required to install MCrypt for PHP 7 on Ubuntu 18.04 LTS

How To Install MCrypt For PHP 7 On Ubuntu 18.04 LTS
How To Install MCrypt For PHP 7 On Ubuntu 18.04 LTS
June 29, 2019

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 of missing MCrypt is that PHP no longer provides it by default and one must explictly install it in order to conitnue using it.

Notes: This tutorial assumes that 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.

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 below mentioned command.

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

# 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"

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.

Write a Comment

Click on the captcha image to get new code.
Discussion Forum by DISQUS