7

This is what I have been doing.

$ sudo apt-get -y install gcc make autoconf libc-dev pkg-config
$ sudo apt-get -y install libmcrypt-de
$ sudo pecl install mcrypt-1.0.2
> libmcrypt prefix? [autodetect] :

Im adding "extension=mcrypt.so" to php.ini

Then I do

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"

I followed these instruction: https://lukasmestan.com/install-mcrypt-extension-in-php7-2/

Lastly I check with php -i | grep mcrypt

This is my output:

PHP Warning:  PHP Startup: mcrypt: Unable to initialize module
Module compiled with module API=20190902
PHP    compiled with module API=20180731
These options need to match
 in Unknown on line 0
/etc/php/7.3/cli/conf.d/20-mcrypt.ini,
/etc/php/7.3/cli/conf.d/mcrypt.ini

I have checked both 20-mcrypt.ini and mcrypt.ini and they look exaclty the same. But my PHP seems to be compiled with the wrong module API. I google around but couldn't find anything specific on that. Any idéas? Thanks!

enter image description here

What I have been using

1 Answers1

10

I've found the solution to same problem.

In my case pecl install mcrypt-1.0.2 diplays something like

...
running: phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
libmcrypt prefix? [autodetect] :

and problem persists also specifyng 20180731 in autodetect.

After some checks I've figured out the problem: php cli runs php 7.3 so I thought that was well configured, but both phpize and php-config are linked to php 7.4!

So you just have to launch the follows:

sudo update-alternatives --set phpize /usr/bin/phpize7.3
sudo update-alternatives --set php /usr/bin/php7.3
sudo update-alternatives --set php-config /usr/bin/php-config7.3

and reistalled a newest version

pecl install mcrypt-1.0.2

That's all.

Note:

  1. eventually run pecl uninstall mcrypt before install the right version
  2. if you don't find phpize7.3 and php-config7.3, try installing via apt-get install php7.3-dev
Sim Sca
  • 413
  • 7
  • 18
  • 2
    Finally a good solution, I've been digging with this for weeks! Thanks! – yehanny Oct 03 '20 at 02:14
  • i have been looking for this solution for the past couple of days. thanks @Sim Sca – manian Dec 28 '20 at 11:56
  • THANK YOU! I have been using pecl command to install mcrypt for PHP7.4, however, it used to give me errors on Homestead telling me build numbers are different since it defaults with PHP8. Update-alternatives commands were the life saver for me. Thanks! – Arda Feb 11 '21 at 22:00