Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem installing mcrypt on PHP 7.3.13 Ubuntu

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

  • https://websiteforstudents.com/install-php-7-2-mcrypt-module-on-ubuntu-18-04-lts/
  • Issue in installing php7.2-mcrypt
  • https://gist.github.com/arzzen/1209aa4a430bd95db3090a3399e6c35f
  • Howto ubuntu 18.04 install / activate PHP extension ext-mcrypt
like image 732
Nicklas Gilbertsson Avatar asked Feb 07 '20 09:02

Nicklas Gilbertsson


1 Answers

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
like image 144
Sim Sca Avatar answered Oct 14 '22 01:10

Sim Sca