如何在 DDEV-Local 的 Web 容器中安装像 mcrypt 这样的 pecl 扩展?

How can I install a pecl extension like mcrypt in DDEV-Local's web container?

在 PHP 7.2 及更高版本中,mcrypt 扩展不再可用,但我的项目依赖于它。我知道该项目不应该使用像 mcrypt 这样古老的东西,但我对此没有任何发言权。我知道 mcrypt 是 removed from PHP7.2+ but is still in pecl.

我可以为该项目做些什么来支持 7.2 及更高版本中的 php-mcrypt?

DDEV-Local 支持自定义 Dockerfile,因此您几乎可以将任何您想要的内容添加到 Web 容器中。参见 docs

这 .ddev/web-build/Dockerfile 将从 pecl 安装 mcrypt 扩展。它使用问题链接中的技术为 PHP_VERSION.

中的 PHP 版本构建 php-mcrypt

如果您想安装不同的 pecl 扩展,您可能只需要少几个包,但思路是一样的。


ARG BASE_IMAGE
FROM $BASE_IMAGE

ENV PHP_VERSION=7.4
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${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 php7.1-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/${PHP_VERSION}/mods-available/ && phpenmod mcrypt