Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freetype-config not found error when we install gd in php7.2-apache in Docker

Tags:

docker

I am trying to install the image php:7.2-apache from a Dockerfile, but I have problem in gd configuration.

I have installed the latest version of docker toolbox 18.09.3 from the page https://github.com/docker/toolbox/releases/tag/v18.09.3 because I have Windows Home 10

The content of the Dockerfile is the following

FROM php:7.2-apache

RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

I have this error configure: error: freetype-config not found. during the construction of the image

checking for the location of libwebp... no
checking for the location of libjpeg... /usr/include/
checking for the location of libpng... no
checking for the location of libz... no
checking for the location of libXpm... no
checking for FreeType 2... /usr/include/
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-webp-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
Service 'apache_php' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y         libfreetype6-dev         libjpeg62-turbo-dev         libpng-dev     && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/     && docker-php-ext-install -j$(nproc) gd' returned a non-zero code: 1

Any solution ?

like image 813
Chen Hanhan Avatar asked Jul 15 '19 20:07

Chen Hanhan


2 Answers

Referring to the reply from https://github.com/docker-library/php/issues/865#issuecomment-511163936 firstly you have to patch and fix the php bug (https://bugs.php.net/bug.php?id=76324)

RUN apt-get update && apt-get install -y pkg-config patch
ADD https://git.archlinux.org/svntogit/packages.git/plain/trunk/freetype.patch?h=packages/php /tmp/freetype.patch
RUN docker-php-source extract; \
  cd /usr/src/php; \
  patch -p1 -i /tmp/freetype.patch; \
  rm /tmp/freetype.patch

then using the following cmd :

RUN docker-php-ext-configure gd --with-freetype-dir --with-jpeg-dir=/usr/include/

I have verified it's working for php7.2-fpm

like image 199
Michael Linus Avatar answered Nov 02 '22 19:11

Michael Linus


This issue is extensively clarified in the related GitHub issue, see in particular this comment.

In brief, the whole issue is related to a change in the default Debian version. Rather than applying patches or taking more complex routes, all that is needed is to add reference to stretch in the FROM line at the beginning of the Dockerfile. In this case, the first line should read:

FROM: php:7.2-apache-stretch

All else should work as expected.

like image 4
giocomai Avatar answered Nov 02 '22 19:11

giocomai