40

I try to install mcrypt in my docker image based on php:7.2-apache. Therefore I use the RUN-Command from the documentation and also answerd here but I receive this error:

error: /usr/src/php/ext/mcrypt does not exist


usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name ...]

   ie: /usr/local/bin/docker-php-ext-install gd mysqli
   /usr/local/bin/docker-php-ext-install pdo pdo_mysql
   /usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop

if custom ./configure arguments are necessary, see docker-php-ext-configure

Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp  gd gettext gmp hash iconv imap interbase intl json ldap mbstring mysqli oci8  odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zend_test zip

Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.
ERROR: Service 'web' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y          libfreetype6-dev          libjpeg62-turbo-dev          libmcrypt-dev          libpng-dev     && docker-php-ext-install -j$(nproc) iconv mcrypt gd mbstring zip' returned a non-zero code: 1

My Dockerfile:

FROM php:7.2-apache

RUN apt-get update && apt-get install -y \
     libfreetype6-dev \
     libjpeg62-turbo-dev \
     libmcrypt-dev \
     libpng-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt gd mbstring zip
#    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
#    && docker-php-ext-install -j$(nproc) gd


COPY ./etc/000-default.conf /etc/apache2/sites-available/

EXPOSE 80

Has anybody an idea how to solve or how to get the needed files in the requested folder?

Thanks!

greeflas
  • 347
  • 1
  • 3
  • 12
Gerrit
  • 1,969
  • 5
  • 28
  • 48
  • 3
    It is best not to use PHP mcrypt, it is abandonware, has not been updated in years and does not support standard PKCS#7 (née PKCS#5) padding, only non-standard null padding that can't even be used with binary data. mcrypt has many outstanding [bugs](https://sourceforge.net/p/mcrypt/bugs/) dating back to 2003. The mcrypt-extension is deprecated will be removed in PHP 7.2. Instead consider using [defuse](https://github.com/defuse/php-encryption) or [RNCryptor](https://github.com/RNCryptor), they provide a complete solution and are being maintained and is correct. – zaph Dec 06 '17 at 14:11

3 Answers3

114

mycrypt extension is not provided with the PHP source since 7.2 , but are instead available through PECL. To install a PECL extension in docker, use pecl install to download and compile it, then use docker-php-ext-enable to enable it:

pecl install mcrypt-1.0.3
docker-php-ext-enable mcrypt
MoiioM
  • 1,549
  • 1
  • 8
  • 11
  • 1
    FYI, I had to remove `mcrypt` from the line where it was trying to install it, as well as add the text in this question. After that, it all seemed to work. – Hans Feb 14 '18 at 15:56
  • @Hans, do you mean `apt-get remove mcrypt` to remove it? – tim Sep 28 '18 at 05:03
  • 2
    you need to install libmcrypt-dev package first – Yehia Nov 16 '18 at 06:49
  • @tim - no, Hans means that his line `docker-php-ext-install -j$(nproc) iconv mcrypt ...` needs to have `mcrypt` removed; mcrypt can't be installed via `docker-php-ext-install` (because mcrypt is no longer available as a normal extension). `pecl install mcrypt-1.0.2` is the command to use now. To make mcrypt available for use, also do enable, as shown in this answer. – ToolmakerSteve Apr 03 '19 at 16:00
  • 1
    And if you want to use it with PHP 7.4, you need to use mcrypt-1.0.3. – Lano Jan 26 '20 at 22:42
18

Building on MoiioM's answer, this worked for me using the 7.2-stretch Docker image from PHP

RUN apt-get update && apt-get install -y libmcrypt-dev \
    && pecl install mcrypt-1.0.2 \
    && docker-php-ext-enable mcrypt
rlorenzo
  • 1,245
  • 1
  • 12
  • 16
10

To install mcrypt extension you have to make sure you did install libmcrypt-dev which is required.

Try to add:

RUN apt install libmcrypt-dev

before you are trying to install extensions for php.

Update

Try to run first:

docker-php-ext-configure mcrypt

and then

docker-php-ext-install mcrypt
Tomasz
  • 3,726
  • 2
  • 25
  • 38
  • 1
    I use that command in my Dockerfile but it is not working. I added it to my post. – Gerrit Dec 06 '17 at 09:53
  • not work either. it says "Possible values for ext-name: bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zend_test zip" – Ary Wibowo Oct 10 '18 at 02:11
  • error: /usr/src/php/ext/libmcrypt-dev does not exist – aswzen Jul 28 '20 at 12:44