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

6
  • First of all I would try to install mcrypt 1.0.3 because it's latest stable now. Also are there other folders under /usr/lib/php/? Commented Feb 7, 2020 at 10:28
  • Alright. Yes 20131226 20151012 20160303 20170718 20180731 20190902 7.0 7.1 7.3 7.4 php-helper php-maintscript-helper sessionclean. Any clue? Commented Feb 7, 2020 at 10:36
  • does the compiled module go only into "20190902"? maybe it's in "20180731" also? Commented Feb 7, 2020 at 12:35
  • Yes it seems like that. the mcrypt.so is in both 2018 and 2019. Should I delete the one in 2018? Commented Feb 7, 2020 at 12:54
  • Probably you can try using extension from extension=/usr/lib/php/20180731/mcrypt.so instead of extension=/usr/lib/php/20190902/mcrypt.so Commented Feb 7, 2020 at 12:57

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

Finally a good solution, I've been digging with this for weeks! Thanks!
i have been looking for this solution for the past couple of days. thanks @Sim Sca
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.