Docker: How to install PHP 7.4 extension ext-http? - php

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?

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

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

Related

Why won't Docker load Tidy?

I'm trying to use phpdocx in order to create a docx file from HTML in a laravel api application.
In order to use this conversion tool, it is necessary to have Tidy installed.
I've included tidy in dockerfile like so
FROM php:7.2-fpm-stretch
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libicu-dev \
openssh-client\
git \
curl \
libmemcached-dev \
libz-dev \
libpq-dev \
libjpeg-dev \
libpng-dev \
tidy \
libfreetype6-dev \
libssl-dev \
libmcrypt-dev \
gnupg \
&& rm -rf /var/lib/apt/lists/*
but when I add a phpinfo(); to my code, tidy is no where to be found.
What is strange is that when I access the bash of docker, I can tidy -v and i get HTML Tidy for Linux version 5.2.0
I have uncommented extension=php_tidy.dll in all the php.ini files associated with the project, and have rebuilt the image numerous times.
When I run check.php included in phpdocx I can find this error in the result Warning You must install Tidy for PHP if you want to use embedHTML in your Word documents.
I've tried docker pull imega/tidy to no avail.
I've been stuck on this for over a day now, if anyone has any idea where I'm going wrong I would appreciate the help.
root#c790d433727a:/var/www/vendor/phpdocx# php check.php
OK PHP version is 7.2.22
OK Zip support is enabled.
OK DOM support is enabled.
OK XML support is enabled.
Warning You must install Tidy for PHP if you want to use embedHTML in your Word documents.
OK mbstring is enabled.
root#c790d433727a:/var/www/vendor/phpdocx# tidy -v
HTML Tidy for Linux version 5.2.0
See an example Docker file:
FROM php:7.2-fpm-stretch
RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y libtidy-dev
RUN docker-php-ext-install -j$(nproc) tidy
if you build it this way:
docker build --tag stackoverflow .
and run this way:
docker run --rm -it --entrypoint="" stackoverflow /bin/sh
you will be logged into CLI and may check installed extensions this way:
php -m
that gives list:
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tidy
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
with:
tidy
under:
[PHP Modules]
Have fun with it :)
I faced the same problem few days ago, problem was not only tidy library self but missed other tidy dependency libtidy-dev, this works perfectly to install and load tidy:
# Install system dependencies
RUN apt-get update && apt-get install -y \
nano \
libxml2-dev \
libzip-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libmagickwand-dev \
**libtidy-dev** \
git \
curl \
zip \
ssh\
wget\
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install \
exif \
gd \
soap \
zip
RUN docker-php-ext-install tidy \
&& docker-php-ext-enable tidy

Docker doesn't install PHP modules

Why are the modules not loaded?
This is my Dockerfile:
FROM php:5.6-apache
# Install PHP extensions and PECL modules.
RUN buildDeps=" \
libbz2-dev \
libmemcached-dev \
libmysqlclient-dev \
libsasl2-dev \
" \
runtimeDeps=" \
curl \
git \
libfreetype6-dev \
libicu-dev \
libjpeg-dev \
libldap2-dev \
libmcrypt-dev \
libmemcachedutil2 \
libpng12-dev \
libpq-dev \
libxml2-dev \
" \
&& apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y $buildDeps $runtimeDeps \
&& docker-php-ext-install bcmath bz2 calendar iconv intl mbstring mcrypt mysql mysqli opcache pdo_mysql pdo_pgsql pgsql soap zip \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ \
&& docker-php-ext-install ldap \
&& docker-php-ext-install exif \
&& pecl install memcached-2.2.0 redis \
&& docker-php-ext-enable memcached.so redis.so \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -r /var/lib/apt/lists/* \
&& a2enmod rewrite
RUN a2enmod rewrite
RUN usermod -u 1000 www-data
RUN usermod -G staff www-data
And this is the output from php -m:
root#3363bf2aa56d:/var/www/html# php -m
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xsl.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20131226/xsl.so: cannot open shared object file: No such file or directory in Unknown on line 0
[PHP Modules]
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
gd
hash
iconv
intl
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
For example, there is no calendar extension, but it is defined in the Dockerfile itself. Also, exif doesn't appear in the list. Whats wrong here?
Solution was, that the php.ini hasn't been updated accordingly.
...
extension=gd.so
extension=calendar.so
extension=exif.so
extension=xdebug.so
extension=soap.so
extension=opcache.so
...
Now it works.
You can add a command in the Dockerfile to activate the extension after building. For example, to enable the calendar extension add:
RUN php5enmod calendar

Deploy Laravel with GitlabCI failed on mcrypt extension

I would like to deploy my Laravel project with GitLabCI and docker. I have a yaml file with the following before_script:
docker-php-ext-install mbstring mcrypt pdo_mysql curl json intl gd xml zip bz2 opcache
Its return with this:
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: Job failed: exit code 1
I tried to install manually the mcrypt with apt-get install following these answers, but nothing worked for me. Cheked this forum post too, but there is no mentioned about this error.
gitlab-ci.yaml file:
before_script:
# Update packages
- apt-get update -yqq
- apt-get install -my wget gnupg
# Upgrade to Node 7
- curl -sL https://deb.nodesource.com/setup_7.x | bash -
# Install dependencies
- apt-get install bzip2 git nodejs libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq
# Install php extensions
- docker-php-ext-install mbstring pdo_mysql curl json intl gd xml zip bz2 opcache
# Install Node dependencies.
# comment this out if you don't have a node dependency
- npm install
- npm install -g bower
- npm install -g gulp-cli
# Install Composer and project dependencies.
- curl -sS https://getcomposer.org/installer | php
- php composer.phar install
Using php7.0 and Laravel 5.3.2
I ran into this issue. Mcrypt was deprecated in PHP 7.2. Here's how to get around it now:
image: php:7.2
before_script:
# Update packages
- apt-get update -yqq
# Install dependencies
- apt-get install git libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq
# Install php extensions
- docker-php-ext-install mbstring pdo_mysql curl json intl gd xml zip bz2 opcache pcntl
....
# PHP 7.2 Mcrypt & pcntl
- pecl install mcrypt-1.0.1
- docker-php-ext-enable mcrypt
....

Docker-php-ext-install mcrypt missing folder

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!
mcrypt 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.5
docker-php-ext-enable mcrypt
Before the pecl install you may need to install/update the package libmcrypt-dev
apt-get update && apt-get install -y libmcrypt-dev
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.4 \
&& docker-php-ext-enable mcrypt
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

Docker service failed to build : return a non-zero code 1

I tried to install some needed extensions for php using docker.
Here is my Dockerfile :
FROM php:7-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
libsqlite3-dev \
libssl-dev \
libcurl3-dev \
libxml2-dev \
libzzip-dev \
&& docker-php-ext-install iconv json mcrypt mbstring mysql mysqli pdo_mysql pdo_sqlite phar curl ftp hash session simplexml tokenizer xml xmlrpc zip \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd
WORKDIR /var/www
CMD ["php7-fpm"]
And here is the error I got :
error: /usr/src/php/ext/mysql 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 mcrypt 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 spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip
ERROR: Service 'php-localdev' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng12-dev libsqlite3-dev libssl-dev libcurl3-dev libxml2-dev libzzip-dev && /usr/local/bin/docker-php-ext-install iconv json mcrypt mbstring mysql mysqli pdo_mysql pdo_sqlite phar curl ftp hash session simplexml tokenizer xml xmlrpc zip && /usr/local/bin/docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && /usr/local/bin/docker-php-ext-install gd'
returned a non-zero code: 1
Do you see any issues in my Dockerfile, or the problem is elsewhere ?
I was inspired for this Dockerfile by the php docker hub.
Thansk for your help.
In the error output, it lists the possible values for ext_name. mysql isn't listed. There is mysqli and pdo_mysql, but not mysql. Your command does include mysql, and the first line of the error seems to be complaining about that. Try taking that out and see if that works.

Categories