PHP intl extension in Docker container - php

I'm trying to load the intl PHP extension in my Docker container, but it doesn't seem to work.
Have already tried this https://github.com/docker-library/php/issues/57 but I still get the same error message:
configure: error: in `/usr/src/php/ext/intl':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
My Docker file looks like this:
RUN apt-get -y update \
&& apt-get install -y libicu-dev\
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl
and it's loading from php:fpm
Have anyone gone through this and got to solve the problem? It's getting me nuts.

Your code worked perfectly for me once I added a space before the backslash terminating the second line of the run command:
RUN apt-get -y update \
&& apt-get install -y libicu-dev \ ### <-- Added space here
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl

It seems some requirements are missing. The snippet below worked for me:
ARG PHP_VERSION=5.6
FROM php:${PHP_VERSION}-fpm-jessie
apt-get install -y zlib1g-dev libicu-dev g++ \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl

Unfortunately, some php extensions have dependencies to other programs. There is a project called docker-php-extension-installer that you can use to install PHP extensions. It will make sure that the required dependencies are present as well. See https://stackoverflow.com/a/56224300/413531 for an example how I actually integrate it in a Dockerfile.

For older build scripts, this problem may be caused by icu-devtools recently dropping icu-config. On debian, it can be fixed by downgrading libicu-dev and icu-devtools:
apt-get install libicu-dev=57.1-6+deb9u4 icu-devtools=57.1-6+deb9u4
To determine the specific version that may work for you, just do:
apt-cache policy libicu-dev
And choose a version up to ~60. Same for icu-devtools.
I found this problem while trying to build a docker image for PHP 7.1. For more context, check debian bug report 920900.

Related

Installing GD extension in Docker

I'm new to Docker and I'm trying to install PHP GD extension.
This is my current Dockerfile:
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install mysqli pdo pdo_mysql bcmath gd
When running the docker via docker-compose build && docker-compose up -d I'm getting a lots of errors and in the end I get this message:
configure: error: Package requirements (zlib) were not met:
Package 'zlib', required by 'virtual:world', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables ZLIB_CFLAGS
and ZLIB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
ERROR: Service 'php' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli pdo pdo_mysql bcmath gd' returned a non-zero code: 1
Without the "gd" at the end the Docker container runs normally.
What could be the problem and how could I fix it?
You can try to add these settings in Dockerfile:
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
Official documentation. Hope it's help you.
In my docker using PHP8.0 I got GD working for jpg,png and webp by adding the following lines to my php.dockerfile:
FROM php:8.0-fpm-alpine
# Install dependencies for GD and install GD with support for jpeg, png webp and freetype
# Info about installing GD in PHP https://www.php.net/manual/en/image.installation.php
RUN apk add --no-cache \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
freetype-dev
# As of PHP 7.4 we don't need to add --with-png
RUN docker-php-ext-configure gd --with-jpeg --with-webp --with-freetype
RUN docker-php-ext-install gd
One more way to approach the issue is to use install-php-extensions in Dockerfile:
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 gd xdebug
Works in Alpine and PHP8.
Docs here
If someone has problems installing php-gd extension in Docker, look up to #Dmitry comment or Documentation and search for "PHP Core Extensions".
You can see full code on my Github, if you want to see how am I running my NGINX and PHP with php-gd extension.

Enable soap for php in docker container

I have been unable to get soap to work with my php Docker setup.
I am using Docker CE for Windows Version 18.03.1-ce-win65 (17513). PHP version 7.2.3
I've tried running from inside the container apt-get install php-soap which results in
Reading package lists... Done
Building dependency tree
Reading state information... Done*
Package php-soap is a virtual package provided by:
* php7.0-soap 7.0.27-0+deb9u1 [Not candidate version]*
E: Package 'php-soap' has no installation candidate
Running docker-php-ext-install soap
results in the error configure: error: libxml2 not found. Please check your libxml2 installation.
However when looking at php info I see the following:
libxml2 Version => 2.9.4
You will need to install libxml2-dev as part of your dockerfile, the image is kept to a minimum and doesn't include all of the bits needed by every module. Although the image may have the main package, the -dev package includes the components needed to compile other modules which rely on it...
RUN apt-get update && \
apt-get install -y libxml2-dev
(From https://github.com/docker-library/php/issues/315)
Just to make it clear - the command
RUN docker-php-ext-install soap
will then run successfully to install the soap library.
For me, working with PHP 7.3.2, the other solutions didn't work.
Both "php-soap" and "php7.3-soap" got "phpXXX-soap has no installation candidate" error.
Alone "docker-php-ext-install soap" wanted the "libxml2-dev" so i just installed the necessities:
FROM php:7.3
RUN apt-get update -y \
&& apt-get install -y \
libxml2-dev \
&& apt-get clean -y \
&& docker-php-ext-install soap
... and it worked nicely.
The correct answer was done, but for me, I needed also to enable (docker-php-ext-enable soap) the soap module, so for If someone could be useful:
FROM php:7.4.24-apache
# your configurations ...
RUN apt-get update && \
apt-get install -y libxml2-dev
RUN docker-php-ext-install soap && docker-php-ext-enable soap
# other configurations ...
This is outside the scope of this repo.
You should get it via this approach:
RUN apt-get update -y \
&& apt-get install -y \
libxml2-dev \
php-soap \
&& apt-get clean -y \
&& docker-php-ext-install soap

Docker php:fpm—install php extensions

I am using the official php:fpm docker image as base for my application container, so the Dockerfile starts like so:
FROM php:fpm
Later in the file I would like to have something like that:
RUN apt-get install -y \
php7.0-gd
But that tells me:
E: Unable to locate package php7.0-gd
E: Couldn't find any package by regex 'php7.0-gd'
»Bashing« into the container using docker exec -it <name> /bin/bash and executing: apt-cache search php | grep gd yields:
php5-gdcm - Grassroots DICOM PHP5 bindings
php5-vtkgdcm - Grassroots DICOM VTK PHP bindings
php5-gd - GD module for php5
So since that is a debian (yessie) based image, only the old php5 packages are available and php7 is installed by some tricky script in the php:fpm dockerfile and it seams that all extensions are compiled within the used php executable.
How can I install more extensions in this scenario?
Quoting https://hub.docker.com/_/php/
How to install more PHP extensions
We provide the helper scripts docker-php-ext-configure, docker-php-ext-install, and docker-php-ext-enable to more easily install PHP extensions.
To install PHP with iconv, mcrypt and GD, they provide the following example:
FROM php:7.0-fpm
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 \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
Please refer to the Dockerhub page for more details.

php 5.3 compilation failed using postgresq93-devel into Docker image

I am using a custom compilation based on PHP 5.3 and I need to upgrade the postgresql version from 9.2 to 9.3.
I am using docker for my infrastructure and the new lines I added was
yum remove postgresql -y && \
rpm -i /tmp/postgresql93.rpm && \
yum install postgresql93 postgresql93-devel -y && \
rm -rf /tmp/postgresql93.rpm && \
The compilation failed and the message was:
checking for pg_config... not found
configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
Then I added the postgresql-devel package into the upgrade lines
yum remove postgresql -y && \
rpm -i /tmp/postgresql93.rpm && \
yum install postgresql-devel postgresql93 postgresql93-devel -y && \
rm -rf /tmp/postgresql93.rpm && \
I wonder why using the postgresql-devel is working if I also installed the postgresql93-devel.
In my previous compilation I was using postgresql-devel but I removed and I thought the postgresql93-devel should be work but it didn't.
Any idea why is this happening? What is the difference here and why do I need to use postgresql-devel either way?

Composer doesn't see GD extension

I've installed GD on Docker machine as described in https://hub.docker.com/_/php/ using:
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
for both PHP 7 and PHP 5.6. It's working without a problem (I can manipulate images) but I want to now install some composer package that requires "ext-gd": "*", and the problem is like this:
php -m
shows gd loaded but
composer show -p
doesn't show ext-gd so I cannot install package I need using composer. Is there any way to install GD to make Composer see it?
I've found similar issue here: https://github.com/composer/composer/issues/4353 but it was closed without resolving. Also composer dependency stating in dont have php-xsl wasn't solved.
For reference I've verified also Homestead and there composer show -p shows ext-gd without a problem also on my localhost (Windows) it's working.
So the only problem I found is with Docker installation. Do you have any clue how can it be solved?
The problem was not directly of Composer but the way I used it.
I had Composer installed in /usr/local/bin/composer but created alias like so:
alias composer="php -n /usr/local/bin/composer"
to not use Xdebug when running composer.
But in fact it was causing all PHP extensions were disabled when running composer so when composer tried to install any package requiring GD2 it didn't see GD2 was installed.

Categories