2

I'm trying to test some PHP code on PHP 5.3 with the GMP extension installed. Here's my Dockerfile:

FROM php:5.3

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906 \
    && apt-get update \
    && apt-get -y install libgmp-dev \ 
    && docker-php-ext-install gmp

When I try to build that I get an error about how docker-php-ext-install doesn't exist.

Here's my second attempt:

FROM php:5.3

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906 \
    && apt-get update \
    && apt-get -y install php5-gmp

That builds without issue but apparently that doesn't actually result in PHP having the GMP extension. I thought maybe I'd need to add extension=gmp.so to the php.ini file but it's not immediately clear to me where that file lives. php -i | grep ini returns, among other things, this:

Configuration File (php.ini) Path => /usr/local/lib

But there's no php.ini file in that directory. I tried to create one but still no luck.

Per chance there's a PHP 5.3 image floating around that already has the GMP extension installed?

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
neubert
  • 15,947
  • 24
  • 120
  • 212

3 Answers3

2

I was able to do it thusly:

FROM php:5.3

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906 \
    && apt-get update \
    && apt-get install -y libgmp-dev wget \
    && ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h \
    && cd /tmp \
    && wget --no-check-certificate https://museum.php.net/php5/php-5.3.29.tar.xz \
    && tar xvf php-5.3.29.tar.xz \
    && cd php-5.3.29/ext/gmp \
    && phpize \
    && ./configure \
    && make \
    && make install \
    && echo extension=gmp.so > /usr/local/lib/php.ini
neubert
  • 15,947
  • 24
  • 120
  • 212
1

Installing PHP extensions works about like this:

FROM php:5.3

RUN apt-key adv --keyserver keyserver.ubuntu.com \
--recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906 \
&& apt-get update && apt-get -y install php5-gmp libgmp \ 
&& echo "extension=gmp.so" > /etc/php5/apache2/conf.d/gmp.ini \
&& /etc/init.d/apache2 reload

But the PHP manual reads:

In order to have these functions available, PHP must be compiled with GMP support by using the --with-gmp option.

So the PHP in the Dockerfile needs to be compiled with the --with-gmp option and libgmp-dev.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • I would have thought that `libgmp-dev` would have been a requirement of `php5-gmp`. None-the-less I added it to my Dockerfile! `docker-php-ext-enable` isn't on my system. I copied the `docker-php-ext-enable` script from your link, did `chmod 777` on it and then did `./docker-php-ext-enable` and got `./docker-php-ext-enable: 5: cd: can't cd to /usr/local/lib/php/extensions/no-debug-non-zts-20090626` back – neubert Oct 06 '19 at 16:26
  • `docker-php-ext-install gmp` gives me a "/bin/sh: 1: docker-php-ext-install: not found" error. `ls -la /usr/local/lib/php` returns data but placing a php.ini file there didn't work. I tried doing `echo "extension=gmp.so;" > /etc/php.ini` to no avail. I also tried `/usr/local/etc/php.ini` as well. `/usr/local/etc/` didn't have a `php` directory so I creatd both that and `conf.d` within `php` and then placed `gmp.ini` within that as your Dockerfile shows. No luck. – neubert Oct 06 '19 at 17:19
  • 1
    @neubert it might be easier to use this [Dockerfile](https://hub.docker.com/r/orsolin/docker-php-5.3-apache/dockerfile) and build from source `--with-gmp=DIR`..it reads `/etc/php5/apache2/conf.d`. – Martin Zeitler Oct 06 '19 at 17:36
0

I use php:8.0-fpm on docker and this worked for me. I hope this work for you too.

RUN apt-get update && apt-get install -y gnupg gnupg2 gnupg1 \
    && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906 \
    && apt-get install -y libgmp-dev --fix-missing \
    && docker-php-ext-install gmp

and if you faced some issue about libreadline8 you can do like bellow.

RUN apt-get install -y libreadline8 --fix-missing
RUN apt-get update && apt-get install -y gnupg gnupg2 gnupg1 --fix-missing
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906
RUN apt-get install -y libgmp-dev --fix-missing
RUN docker-php-ext-install gmp
adnan ahmady
  • 770
  • 1
  • 7
  • 12
  • That's pretty much what I tried to do in the first Dockerfile I posted but, as my original post said, "_when I try to build that I get an error about how `docker-php-ext-install` doesn't exist_". I guess the php:5.3 doesn't have that. Anyway, the solution is marked off as the answer. Certainly a better answer might exist but for PHP 5.3 your approach doesn't work. I mean, it'd be a better approach if it did but it doesn't – neubert Nov 13 '21 at 14:58