How to install mcrypt on PHP 7.3.3 ubuntu
Asked Answered
S

4

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

Scruff answered 14/4, 2019 at 17:22 Comment(3)
mcrypt relies on libmcrypt which is dead and has been unmaintained since 2007. Use openssl insteadModulator
php.net/manual/en/migration71.deprecated.phpModulator
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.Valleau
S
34

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://mcmap.net/q/841879/-how-to-install-mcrypt-on-php-7-3-3-ubuntu

Schwenk answered 21/11, 2019 at 1:51 Comment(3)
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 mcryptColossus
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.7Meritocracy
@Meritocracy for php > 7.4 you will need to install the next version sudo pecl install mcrypt-1.0.3Cattail
G
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

Groschen answered 14/4, 2019 at 17:24 Comment(2)
php.net/manual/en/migration71.deprecated.php Just because you can does not mean you should :)Modulator
There is an option: github.com/PrestaShop/PrestaShop/commit/…. 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).Valleau
D
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

Dekameter answered 30/5, 2019 at 8:53 Comment(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.Bun
C
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
Crepitate answered 4/2, 2021 at 17:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.