7

I would like to install the ext-http extension because I have this error when I execute composer install command in my php-apache container:

The requested PHP extension ext-http * is missing from your system. Install or enable PHP's http extension.

My Dockerfile:

ARG PHP_VERSION=""

FROM php:${PHP_VERSION}-apache

ENV COMPOSER_ALLOW_SUPERUSER=1

EXPOSE 80
WORKDIR /${PROJECT_DIRECTORY}

# git, unzip & zip are for composer
RUN apt-get update -qq && \
    apt-get install -qy \
    git \
    gnupg \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libmcrypt-dev \
    libicu-dev \
    libxml2-dev \
    wget \
    nano \
    unzip \
    zip && \
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# PHP Extensions
RUN docker-php-ext-install -j$(nproc) opcache pdo_mysql intl xml soap
ADD php/php.ini /usr/local/etc/php/conf.d/${PROJECT_DIRECTORY}.ini

# Apache
RUN a2enmod rewrite remoteip
ADD vhosts/vhost.conf /etc/apache2/sites-available/000-default.conf

I have "ext-http": "*" in require node of my composer.json.

I tried:

RUN docker-php-ext-install -j$(nproc) opcache pdo_mysql intl xml soap ext-http

And I have this error:

Step 7/10 : RUN docker-php-ext-install -j$(nproc) opcache pdo_mysql intl xml soap ext-http ---> Running in 8ef2c127b632 error: /usr/src/php/ext/ext-http 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 ffi fileinfo filter ftp gd gettext gmp hash iconv imap 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 reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer 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 'apache' failed to build: The command '/bin/sh -c docker-php-ext-install -j$(nproc) opcache pdo_mysql intl xml soap ext-http' returned a non-zero code: 1 Failed to deploy 'Compose: .docker': docker-compose process finished with exit code 1

How can I install this extension please?

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Valentin Harrang
  • 1,081
  • 2
  • 17
  • 34

2 Answers2

11

I published a script that lets you install the http PHP extension (and many others) with just these lines:

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
    install-php-extensions http

the script takes care of the PHP version, and installs all the required APT (for Debian) or APK (for Alpine) packages.

More details here: https://github.com/mlocati/docker-php-extension-installer

Michele Locati
  • 1,655
  • 19
  • 25
3

You might want to install it via pecl. The http extension also has dependencies.

RUN  docker-php-ext-install hash iconv \
&& pecl install raphf propro \
&& docker-php-ext-enable raphf propro \
&& pecl install pecl_http \
&& echo -e "extension=raphf.so\nextension=propro.so\nextension=http.so" > /usr/local/etc/php/conf.d/docker-php-ext-http.ini \
&& rm -rf /usr/local/etc/php/conf.d/docker-php-ext-raphf.ini \
&& rm -rf /usr/local/etc/php/conf.d/docker-php-ext-propro.ini 

I've got the inspiration via https://hub.docker.com/r/realpaul/docker-php/dockerfile

Christian
  • 27,509
  • 17
  • 111
  • 155
Tschallacka
  • 27,901
  • 14
  • 88
  • 133
  • 1
    I would add a note, here installing that the hash extension is probably not needed since it is installed in the PHP image by default, or if installing the hash extension causes an error, try skipping that step and continue. – Manish M Demblani May 23 '21 at 16:27