13

I tried to follow: PHP Warning: PHP Startup: Unable to load dynamic library 'mcrypt.so'

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

I get:

pecl/mcrypt requires PHP (version >= 7.2.0, version <= 7.3.0, excluded versions: 7.3.0), installed version is 7.3.3-1+ubuntu14.04.1+deb.sury.org+1
No valid packages found
install failed

I use prestashop which require this

Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66
Elia Weiss
  • 8,324
  • 13
  • 70
  • 110
  • 5
    mcrypt relies on libmcrypt which is dead and has been unmaintained since 2007. Use openssl instead – RiggsFolly Apr 14 '19 at 17:29
  • 3
    https://www.php.net/manual/en/migration71.deprecated.php – RiggsFolly Apr 14 '19 at 17:31
  • 1
    Partition prestashop to upgrade and move away from mcrypt, they have had years to do so and still haven't. There is no way I would trust prestashop since they cant make the simple effort to change to libraries for such a critical part of their shopping system. Remember, the risk is on you to run software that is using deprecated obsolete old code. – Geoffrey Apr 14 '19 at 18:00

4 Answers4

33

If anyone is using an AWS bitnami install w/ php7.3.10, the following is a layout with appropriate file paths (references listed below)

Check your PHP version

$ php -version

Install mcrypt extension

$ sudo apt-get -y install gcc make autoconf libc-dev pkg-config
$ sudo apt-get -y install libmcrypt-dev

If php version > 7.3.0

$ sudo pecl install mcrypt-1.0.2

Or the newest version: https://pecl.php.net/package/mcrypt

If php version <= 7.3.0

$ sudo pecl install mcrypt-1.0.1

When you are shown the prompt (Press [Enter] to autodetect)

> libmcrypt prefix? [autodetect] :

enable mcrypt in php.ini -> check if mcrypt is already in php.ini and maybe just needs to be uncommented

$ more /opt/bitnami/php/etc/php.ini | grep mcrypt
;extension=mcrypt.so

Add or uncomment extension=mcrypt.so in php.ini

$ emacs /opt/bitnami/php/etc/php.ini

REFERENCES...

https://lukasmestan.com/install-mcrypt-extension-in-php7-2/

How to install mcrypt on PHP 7.3.3 ubuntu

https://stackoverflow.com/a/55678046/2298002

Community
  • 1
  • 1
greenhouse
  • 1,231
  • 14
  • 19
  • 1
    Couple notes: (1) I needed to install php7.3-dev for this to work. OP mentions it, but it's not mentioned in any of the answers. Also, I prefer to install module like: `bash -c "echo extension=/path/to/mcrypt.so > /etc/php/7.3/mods-available/mcrypt.ini"` and then `phpenmod mcrypt` – But those new buttons though.. Feb 24 '20 at 12:59
  • For what it's worth this is the best answer, but needs to be updated to: If php version >= 7.2.0, version <= 7.4.0. I just tried to install with these commands on 7.4.7 and got this error: pecl/mcrypt requires PHP (version >= 7.2.0, version <= 7.4.0, excluded versions: 7.4.0), installed version is 7.4.7 – stevenbranigan82 Jul 09 '20 at 20:26
  • @stevenbranigan82 for php > 7.4 you will need to install the next version `sudo pecl install mcrypt-1.0.3` – Kevin Lynch Nov 11 '20 at 14:36
17

You have to install version 1.0.2.

The error message clearly tells you 1.0.1 supports only PHP 7.2, not 7.3.

It's all documented on the official pecl/mcrypt page.

Release 1.0.2:

PHP Version: PHP version 7.4.0 or older

PHP Version: PHP 7.2.0 or newer

PEAR Package: PEAR 1.4.0 or newer

Release 1.0.1:

PHP Version: PHP version 7.3.0 or older

PHP Version: PHP 7.2.0 or newer

PEAR Package: PEAR 1.4.0 or newer

Community
  • 1
  • 1
Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66
  • 3
    https://www.php.net/manual/en/migration71.deprecated.php Just because you can does not mean you should :) – RiggsFolly Apr 14 '19 at 17:31
  • There is an option: https://github.com/PrestaShop/PrestaShop/commit/80ecf62a30fbd2521007ad3eee441d055aa49c36#diff-520d48568b8aff46bd7f612f3f425783. Even still though they are not doing things here correctly as they are not padding/packing the encrypted data it a secure manner (HMAC signed, etc). – Geoffrey Apr 14 '19 at 18:06
7

Use this, it's working perfectly in php-7.3:

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

Autodetect: HIT ENTER

sudo bash -c "echo extension=/usr/lib/php/[folder in your pc]/mcrypt.so > /etc/php/7.3/cli/conf.d/mcrypt.ini"
sudo bash -c "echo extension=/usr/lib/php/[folder in your pc]/mcrypt.so > /etc/php/7.3/apache2/conf.d/mcrypt.ini"

php -i | grep mcrypt

Glen Solsberry
  • 11,960
  • 15
  • 69
  • 94
Sridhar
  • 81
  • 1
  • 1
  • Completing your answer, it is necessary to do this to: `sudo bash -c "echo extension=/usr/lib/php/[folder in your pc]/mcrypt.so > /etc/php/7.3/mods-availabl e/mcrypt.ini"` So, php will be able to find the module. – bbruno5 Sep 21 '19 at 00:11
2

I have solved same issue in PHP Version : 7.4.3 Ubuntu Version : 20.04.1 LTS and nginx

sudo apt-get install php-pear php7.4-dev
sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libmcrypt-dev

You can choose your mcrypt version according to php version Read

  sudo pecl install mcrypt-1.0.4

When you are shown the prompt

libmcrypt prefix? [autodetect] :

Press [Enter] to autodetect.

The output will be something like this.

Build process completed successfully
Installing '/usr/lib/php/20190902/mcrypt.so'
install ok: channel://pecl.php.net/mcrypt-1.0.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=mcrypt.so" to php.ini

After success installing mcrypt using pecl, you should add extension=/usr/lib/php/20190902/mcrypt.so extension to php.ini.

I have added extension=/usr/lib/php/20190902/mcrypt.so in bellow files

  1. /etc/php/7.4/fpm/php.ini
  2. /etc/php/7.4/cli/php.ini

Restart You nginx because i am using nginx

systemctl restart nginx

You can also restart php-fpm

sudo service php7.4-fpm restart

Finally how can verify mycrpt is installed or not (Note close your terminal and open again)

 php -m | grep mcrypt
Nanhe Kumar
  • 15,498
  • 5
  • 79
  • 71