How to install mcrypt in php7.2 ubuntu

Nov 27, 2018 · 2 min read

Steps to Install mcrypt extension in ubuntu server.

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libmcrypt-dev
sudo pecl install mcrypt-1.0.1

One important thing I got when I try to install mcrypt in server
I got below error.

PHP Warning:  PHP Startup: Unable to load dynamic library '' (tried: /usr/lib/php/20170718/ (/usr/lib/php/20170718/ cannot open shared object file: No such file or directory), /usr/lib/php/20170718/ (/usr/lib/php/20170718/ cannot open shared object file: No such file or directory)) in Unknown on line 0
WARNING: channel "" has updated its protocols, use "pecl channel-update" to update
downloading mcrypt-1.0.1.tgz ...
Starting to download mcrypt-1.0.1.tgz (33,782 bytes)
.........done: 33,782 bytes
PHP Fatal error: Cannot use result of built-in function in write context in /usr/share/php/Archive/Tar.php on line 639

If you got same error like above you have to open Tar.php file and update
$v_att_list = &func_get_args();
$v_att_list &= func_get_args();

Now you need run this command again.

sudo pecl install mcrypt-1.0.1

When you see the prompt

libmcrypt prefix? [autodetect] :

Press Enter to autodetect.

After successfully installed mcrypt through pecl, you should add extension to php.ini.

The output will look like this:

Build process completed successfully
Installing ‘/usr/lib/php/20170718/’
install ok: channel://
configuration option “php_ini” is not set to php.ini location
You should add “” to php.ini

Get installed path and add to cli and apache2 in php.ini configuration file.

sudo bash -c "echo extension=/usr/lib/php/20170718/ > /etc/php/7.2/cli/conf.d/mcrypt.ini"sudo bash -c "echo extension=/usr/lib/php/20170718/ > /etc/php/7.2/apache2/conf.d/mcrypt.ini"

Restart server

sudo /etc/init.d/apache2 restart

Now time to verify extension is installed or not.

php -i | grep "mcrypt"

Output will look like this:

Registered Stream Filters => zlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*, convert.iconv.*
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value


Written by

web developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade