How to install mcrypt in php7.2 ubuntu

prabhatsinh
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 'mcrypt.so' (tried: /usr/lib/php/20170718/mcrypt.so (/usr/lib/php/20170718/mcrypt.so: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mcrypt.so.so (/usr/lib/php/20170718/mcrypt.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" 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();
To
$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 mcrypt.so extension to php.ini.

The output will look like this:


Build process completed successfully
Installing ‘/usr/lib/php/20170718/mcrypt.so’
install ok: channel://pecl.php.net/mcrypt-1.0.1
configuration option “php_ini” is not set to php.ini location
You should add “extension=mcrypt.so” 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/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"

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
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value

prabhatsinh

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