Docker doesn't install PHP modules - php

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

Related

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

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

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

Class ZipArchive not found using Docker [duplicate]

This question already has answers here:
Fatal error: Class 'ZipArchive' not found in
(25 answers)
Closed 3 months ago.
I have the following error on my docker machine/instance:
Class 'ZipArchive' not found
Here is my Dockerfile:
FROM php:7.2-alpine
RUN docker-php-ext-install sockets pdo_mysql
RUN docker-php-ext-install -j$(nproc) \
zip
ADD consumer /opt/craft/app/
ADD app.tar.gz /opt/craft/app
CMD /opt/craft/app/consumer
When I sh in to the container via docker-run, I can do php -m:
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
zip is not there. Is it supposed to be there? I have also tried doing:
/opt/craft/app # apk add zip
OK: 17 MiB in 29 packages
/opt/craft/app # php -m
But zip still isn't available and I still get the same output error ziparchive not found.
I'm quite new to docker and installing php modules by myself.
How do I get ZipArchive class installed? (Ideally through dockerfile).
Actually when I faced Laravel excel problem on php-fpm 7.4 on docker, I find your question. And this answer
RUN apk update \
&& apk upgrade \
&& apk add zlib-dev \
&& docker-php-ext-configure zip --with-zlib-dir=/usr \
&& docker-php-ext-install zip
don't working forme
I think this Dockerfile works fine for you
FROM php:7.4-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
RUN apt-get update && \
apt-get install -y \
libzip-dev \
&& docker-php-ext-install zip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
try replace
RUN docker-php-ext-install -j$(nproc) \
zip
with
RUN apk update \
&& apk upgrade \
&& apk add zlib-dev \
&& docker-php-ext-configure zip --with-zlib-dir=/usr \
&& docker-php-ext-install zip
in Dockerfile
I tried it and it worked.

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

Troubles with Docker + PHP7 + GD resulting in "Call to undefined function imagecreatefromjpeg()"

I'm having troubles when trying to create an image using imagecreatefromjpeg using this Dockerfile to generate the container:
FROM php:7.1-apache
RUN apt-get update && \
apt-get install -y -qq git \
libjpeg62-turbo-dev \
apt-transport-https \
libfreetype6-dev \
libmcrypt-dev \
libpng12-dev \
libssl-dev \
zip unzip \
nodejs \
npm \
wget \
vim
RUN pecl install redis && docker-php-ext-enable redis
RUN docker-php-ext-install -j$(nproc) iconv mcrypt zip pdo pdo_mysql gd bcmath
COPY ./containers/yii.conf /etc/apache2/sites-available/000-default.conf
RUN for mod in rewrite headers; do a2enmod $mod; done && service apache2 restart
WORKDIR /var/www/html/
GD was correctly installed (libjpeg too - both appearing in php -i and phpinfo()) but imagecreatefromjpeg does not works and I don't know why.
I also ran apt install libjpeg-dev libpng-dev libfreetype6-dev trying to ~force~ reinstallation (or reconfiguration) but seems doesn't succeded (yes, I also restart the container).
root#e8db647c96c4:/var/www/html# php -i | grep -i GD
/usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
gd
GD Support => enabled
GD Version => bundled (2.1.0 compatible)
gd.jpeg_ignore_warning => 1 => 1
root#e8db647c96c4:/var/www/html#
root#e8db647c96c4:/var/www/html# docker-php-ext-enable gd
warning: gd (gd.so) is already loaded!
root#e8db647c96c4:/var/www/html#
I've tried apt install libgd2-xpm-dev* and apparently it doesn't solves the problem.
Solved
I was missing to put
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
into my Dockerfile.
Full revised Dockerfile:
FROM php:7.1-apache
RUN apt-get update && \
apt-get install -y -qq git \
libjpeg62-turbo-dev \
apt-transport-https \
libfreetype6-dev \
libmcrypt-dev \
libpng12-dev \
libssl-dev \
zip unzip \
nodejs \
npm \
wget \
vim
RUN pecl install redis && docker-php-ext-enable redis
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) iconv mcrypt zip pdo pdo_mysql gd bcmath
COPY ./containers/yii.conf /etc/apache2/sites-available/000-default.conf
RUN for mod in rewrite headers; do a2enmod $mod; done && service apache2 restart
WORKDIR /var/www/html/
PHP 7.4 (Alpine)
If anybody is struggling to enable JPEG support in GD with PHP 7.4, here's what I had to do in order to be able to use imagecreatefromjpeg() function.
My example is based on Alpine 3.10, if you're using other distribution adjust it to your needs.
First install dependencies, in my case beside JPEG I need support for PNG files.
apk add jpeg-dev libpng-dev
After that we can run docker-php-ext-configure command to configure our gd with JPEG support. Notice that flag --with-jpeg-dir was changed to --with-jpeg and we don't need to provide flag to enable PNG. More you can read in PHP 7.4 Changelog in GD section.
docker-php-ext-configure gd --with-jpeg
Directly after that let's run docker-php-ext-install to install GD itself.
docker-php-ext-install -j$(nproc) gd
FULL EXAMPLE
FROM php:7.4-fpm-alpine3.10
RUN apk add jpeg-dev libpng-dev \
&& docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
For PHP 5.6
FROM php:5.6-apache
RUN apt-get update && apt-get install -y \
libfreetype6-dev libjpeg62-turbo-dev \
libgd-dev libpng12-dev
RUN docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
If still not working, can re-install the container.
docker rm <container id>
docker-compose build --pull
docker-compose up
Updated Version PHP 7.4 + Apache:
Dockerfile
FROM php:7.4-apache
RUN apt-get update -y && apt-get install -y sendmail libpng-dev libfreetype6-dev libjpeg62-turbo-dev libgd-dev libpng-dev
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-configure gd \
--with-freetype=/usr/include/ \
--with-jpeg=/usr/include/
RUN docker-php-ext-install gd
...
Add these Commands
docker-php-ext-configure gd --with-freetype --with-jpeg
docker-php-ext-install -j$(nproc) gd
Working full Dockerfile:
FROM php:7.4-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /src/
# Set working directory
WORKDIR /src
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg-dev \
libwebp-dev \
libxpm-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install pdo_mysql exif pcntl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install --prefer-source --no-interaction
COPY . /src
RUN chmod 777 -R /src/storage
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]

Categories