2

In PHP 7.2 and higher the mcrypt extension is no longer available, but my project depends on it. I know that the project shouldn't be using something as ancient as mcrypt, but I don't have any say in this. I know that mcrypt was removed from PHP7.2+ but is still in pecl.

What can I do for this project to support php-mcrypt in 7.2 and higher?

rfay
  • 9,963
  • 1
  • 47
  • 89

1 Answers1

4

DDEV supports custom Dockerfiles, so you can add almost anything you want to the web container. See docs.

This .ddev/web-build/Dockerfile will install the mcrypt extension from pecl. It uses the techniques in the links in the question to build php-mcrypt for the PHP version in DDEV_PHP_VERSION (which is provided by the build process).

If you wanted to install a different pecl extension, you might need just a few less packages, but the idea is the same.

RUN disable_xdebug 
RUN if [ ! -f /usr/bin/sed ]; then ln -sf /bin/sed /usr/bin/sed; fi
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confnew" --no-install-recommends --no-install-suggests build-essential make autoconf libc-dev pkg-config php-pear php${DDEV_PHP_VERSION}-dev libmcrypt-dev
# The "echo" below just forces accepting the "automatic" configuration, the same as hitting <RETURN>
RUN echo | sudo pecl install mcrypt
# Because php${DDEV_PHP_VERSION}-mcrypt is already installed in web container we can just copy its mcrypt.ini
RUN cp /etc/php/7.1/mods-available/mcrypt.ini /etc/php/${DDEV_PHP_VERSION}/mods-available/ && phpenmod mcrypt

rfay
  • 9,963
  • 1
  • 47
  • 89
  • FYI this doesn't work with ddev 1.17 due to repository changes in the Ubuntu world. – Damien McKenna May 17 '21 at 06:27
  • Made minor updates for current usage and seems to work fine. Updated to php7.4. Should work for you @DamienMcKenna - let me know. – rfay May 17 '21 at 13:47
  • That worked, thank you! FYI the output gave lots of weird errors that various libraries couldn't be found, the solution was indeed to change PHP to 7.4. That said, would it still work if you wanted / needed to run an older PHP build? – Damien McKenna May 18 '21 at 14:21
  • Weirdly phpize with 7.3 had a hard-wired path to sed in /usr/bin/sed. Anyway, I updated slightly to handle that and tried with 7.3 and it worked fine. – rfay May 19 '21 at 15:17