Skip to content

Installing gd on buster results in freetype-config not found #865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
StefanPrintezis opened this issue Jul 13, 2019 · 32 comments · Fixed by #869
Closed

Installing gd on buster results in freetype-config not found #865

StefanPrintezis opened this issue Jul 13, 2019 · 32 comments · Fixed by #869

Comments

@StefanPrintezis
Copy link

StefanPrintezis commented Jul 13, 2019

Not using cached versions.
I've tested the install on another device, same output.

Dockerfile:

FROM php:7.3.7-fpm
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/freetype --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd \
    && rm -r /var/lib/apt/lists/*

configure: error: freetype-config not found.
ERROR: Service 'php' failed to build: The command '/bin/sh -c apt update && apt install -y --no-install-recommends         libfreetype6-dev         libjpeg62-turbo-dev         libpng-dev     && docker-php-ext-install -j$(nproc) iconv     && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/     && docker-php-ext-install -j$(nproc) gd     && rm -r /var/lib/apt/lists/*' returned a non-zero code: 1

The issue is present when using the latest version 7.3.7-fpm (buster)
The build succeeds when using 7.3.6-fpm (stretch)

TLDR solution for now
Use a tag with stretch instead of buster.

@StefanPrintezis
Copy link
Author

StefanPrintezis commented Jul 13, 2019

This might be related switching to buster from stretch?

@jeyk
Copy link

jeyk commented Jul 13, 2019

This might be related switching to buster from stretch?

Probably. The changelog for libfreetype6-dev states:

  • The `freetype-config' script is no longer installed by default
    (Closes: #871470, #886461). All packages depending on libfreetype6-dev
    should use pkg-config to find the relevant CFLAGS and libraries.

I guess that docker-php-ext-configure gd didn't anticipate this change...

@StefanPrintezis
Copy link
Author

So somewhere this should be added?:

pkg-config freetype2 --libs
pkg-config freetype2 --cflags

Not sure where yet.

@marcingajda
Copy link

marcingajda commented Jul 13, 2019

For people looking here for a QUICK FIX

Set the version of used image to stretch.

If you use for example PHP-FPM 7.3 then in your Dockerfile replace this:

FROM php:7.3-fpm

with this:

FROM php:7.3-fpm-stretch

Works for me and the error is gone.

@rjocoleman
Copy link

This shouldn't be an issue with PHP 7.4 because of the migration to pkg-config. https://github.com/php/php-src/blob/PHP-7.4/UPGRADING#L606

This has been a problem for a wee while for linux distros like Arch that have newer versions running.
https://bugs.php.net/bug.php?id=76324

The patch here adds dection via pkg-config https://git.archlinux.org/svntogit/packages.git/tree/trunk/freetype.patch?h=packages/php
(pkg-config freetype2 --cflags and pkg-config freetype2 --libs as @StefanPrintezis notes)

Extracting the PHP source early in your Dockerfile and patching it is one way to work around this.

FROM php:7.3.7-fpm

RUN apt-get update; \
  apt-get install -y --no-install-recommends \
  libfreetype6-dev \
  libjpeg62-turbo-dev \
  libpng-dev \
  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

RUN docker-php-ext-configure gd --with-gd --with-freetype-dir 

I added patch and pkg-config in the example for clarity, I didn't check to see if they're included in the buster image by default.

@andreasschroth
Copy link

Kind of OT, but is it really such a good idea to switch OS version within a minor release? Didn't expect a switch from Stretch to Buster from 7.3.6 to 7.3.7. Pretty unexpected.

@barnabas-szekeres
Copy link

The issue also exist in php:7.2-apache image :(

@tvanro
Copy link

tvanro commented Jul 15, 2019

Same issue with wordpress:5.2.2-apache (that's building FROM php:7.3-apache)

FROM wordpress:5.2.2-apache
RUN apt-get update && apt-get install -y \
		libfreetype6-dev \
		libjpeg62-turbo-dev \
		libpng-dev \
	&& docker-php-ext-install -j$(nproc) iconv \
	&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
	&& docker-php-ext-install -j$(nproc) gd
configure: error: freetype-config not found.
ERROR: Service 'wordpress_apache' 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-install -j$(nproc) iconv 	&& 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

@euphoriatek
Copy link

Same issue on php:7.2-fpm image

image: php:7.2-fpm

this line is failing: - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/

it started happening recently.

@jxlwqq

This comment has been minimized.

@andreasschroth
Copy link

andreasschroth commented Jul 15, 2019

Temporary use:

FROM php:7.2.19-apache

or:

FROM php:7.3.6-apache

No, not really a good idea. You'll end up stuck with 7.2.19 or 7.3.6 and won't receive any security fixes, etc. anymore.

Better use this:

FROM php 7.2-apache-stretch

or:

FROM php 7.3-apache-stretch

@andreasschroth
Copy link

andreasschroth commented Jul 15, 2019

Same issue on php:7.2-fpm image

image: php:7.2-fpm

this line is failing: - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/

it started happening recently.

Use a base image based on Debian Stretch instead of Buster:

FROM php 7.2-fpm-stretch

@euphoriatek

This comment has been minimized.

@andreasschroth
Copy link

andreasschroth commented Jul 15, 2019

I believe most people here don't really understand what's happening / going on.

The latest released docker images with the default tags (e.g. php:7.3-fpm) are now based on Debian Buster instead of Debian Stretch before.

Debian Buster uses a more up-to-date version of the libfreetype6-dev (libfreetype6) package (version 2.9.1-3 instead of 2.6.3-3.2 before). But Version 2.9.1-3 isn't shipped with freetype-config anymore, as it was removed and the package maintainers recommend to replace calls to freetype-config by calls to pkg-config.

So as I have already commented a few times before here: Switch to the tags suffixing with -stretch. E.g. instead of using php:7.3-fpm you use php:7.3-fpm-stretch. Or instead of php:7.2-apache you use php:7.2-apache-stretch. That's it.

@jvanoosterom

This comment has been minimized.

@euphoriatek
Copy link

I believe most people here don't really understand what's happening / going on.

The latest released docker images with the default tags (e.g. php:7.3-fpm) are now based on Debian Buster instead of Debian Stretch before.

Debian Buster uses a more up-to-date version of the libfreetype6-dev (libfreetype6) package (version 2.9.1-3 instead of 2.6.3-3.2 before). But Version 2.9.1-3 isn't shipped with freetype-config anymore, as it was removed and the package maintainers recommend to replace calls to freetype-config by calls to pkg-config.

So as I have already commented a few times before here: Switch to the tags suffixing with -stretch. E.g. instead of using php:7.3-fpm you use php:7.3-fpm-stretch. Or instead of php:7.2-apache you use php:7.2-apache-stretch. That's it.

for those using 7.2-fpm image using 7.2-fpm-stretch not worked but instead 7.2.20-fpm-stretch worked

@goetas
Copy link

goetas commented Jul 15, 2019

same issue with php:7.1-fpm, solved with changing version to php:7.1-fpm-stretch (as @jvanoosterom did)

@juuuuuu

This comment has been minimized.

@moqmar

This comment has been minimized.

@goetas
Copy link

goetas commented Jul 15, 2019

This can be reproduced running just

docker run --rm php:7.1.30 bash -c 'apt-get update -qq && apt-get install libfreetype6-dev -y -qq && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/'

@tianon
Copy link
Member

tianon commented Jul 15, 2019

This is a known issue in PHP upstream: https://bugs.php.net/bug.php?id=76324

For PHP 7.4+ (still a pre-release), the solution is to simply use --with-freetype and it will use pkg-config as appropriate to find freetype.

For older PHP releases, the solution is more complicated and likely involves some variation of https://git.archlinux.org/svntogit/packages.git/tree/php/trunk/freetype.patch, which IMO should really be applied as a backport upstream for handling pkg-config as a fallback in conjunction with freetype-config. We might need to consider applying something like that to our builds, but that's a solution of last resort -- we provide a stock PHP upstream experience as much as possible, and applying patches that ought to be applied upstream is something we try to strongly avoid.

For many users, the solution is likely going to be switching to explicitly use -stretch as described above. To be clear, this is exactly what those Debian release named aliases were added for, and why the stretch variants are not deprecated/removed yet.

@StefanPrintezis StefanPrintezis changed the title 7.3.7 installing gd results in freetype-config not found Installing gd on buster results in freetype-config not found Jul 15, 2019
@gries
Copy link

gries commented Jul 16, 2019

I'm curious on why the switch to buster was done "silently" by that I mean why isn't strech still the default and -buster an option? it just confused me as php at least since 7.* times is all about bc compatibility and this somewhat goes against that philosophy.

eerotal pushed a commit to eerotal/LibreSignage that referenced this issue Jul 16, 2019
- This is a workaround for docker-library/php#865 which broke all
  LibreSignage Docker builds. The workaround will be used for the time
  being.
@wglambert
Copy link

Stretch isn't the default because Buster is now the "stable" version of Debian which is considered the "official release"
https://wiki.debian.org/DebianStability

There isn't a particularly great way of notifying users of changes outside of them checking the commits or pull requests

Using explicit tags would help to prevent breakage from an update since php-7.3-fpm-stretch will resolve to the same base OS even when the default tag changes to a different one, specifying the OS variant is along the same lines as specifying version numbers. Just as you might not want to use the tag php:7.3-fpm-alpine as you'll be updated to any major OS changes, but instead php:7.3-fpm-alpine3.10 which will just provide minor updates to 3.10.

Going a step further if a breakage is of particular concern then using the image's sha256 digest will lock you to that specific version in time, so that you could then test updates for utmost compatibility.

For a full list of tags see https://github.com/docker-library/docs/blob/master/php/README.md#supported-tags-and-respective-dockerfile-links

@regiszanandrea

This comment has been minimized.

dargmuesli added a commit to dargmuesli/jonas-thelemann that referenced this issue Jul 19, 2019
@cnlyzy
Copy link

cnlyzy commented Jul 19, 2019

FROM php:fpm

also have this probrem, change to

FROM php:fpm-stretch

It Works for me and the error is gone.

tianon added a commit to docker-library/drupal that referenced this issue Jul 19, 2019
The plan is to switch to buster once docker-library/php#865 is resolved in a clean way (either in the PHP image or in PHP itself).
tianon added a commit to infosiftr/php that referenced this issue Jul 19, 2019
…on buster

See:

- docker-library#865
- https://bugs.php.net/bug.php?id=76324
- php/php-src#3632
- php/php-src@2d03197

This is not necessary for Debian Stretch (where `freetype-config` still exists) nor PHP 7.4+ (where `pkg-config` is used instead/in addition).
Toilal added a commit to inetum-orleans/generator-docker-devbox that referenced this issue Jul 22, 2019
shaunthegeek added a commit to wifidog/wifidog-auth-laravel that referenced this issue Aug 2, 2019
@MichaelBrenden
Copy link

MichaelBrenden commented Nov 22, 2019

# I just hit this bug while installing php-7.3.12 onto debian 10.1

# Freetype 2.10.1 (and maybe earlier) offers a configure option to compile its much-missed freetype-config:

cd /usr/local/src/freetype-2.10.1
./configure --prefix=/usr/local/freetype-2.10.1 --enable-freetype-config

# Then tell php configure about it

cd /usr/local/src/php-7.3.12
./configure --with-freetype-dir=/usr/local/freetype-2.10.1

@perecedero
Copy link

For those still using the freetype.patch here is a working URL.
https://git.archlinux.org/svntogit/packages.git/plain/trunk/freetype.patch?h=packages/php&id=a8e8e87f405e0631b2a4552656413735ebf9457c

@JulianKingman

This comment was marked as off-topic.

@yosifkit

This comment was marked as off-topic.

VenusPR pushed a commit to VenusPR/PHP_Project that referenced this issue Mar 12, 2023
…on buster

See:

- docker-library/php#865
- https://bugs.php.net/bug.php?id=76324
- php/php-src#3632
- php/php-src@2d03197

This is not necessary for Debian Stretch (where `freetype-config` still exists) nor PHP 7.4+ (where `pkg-config` is used instead/in addition).
@fhuitelec
Copy link

For wanderers like myself, here's an adaptation of #865 (comment) with the right patch file:

ADD https://gitlab.archlinux.org/archlinux/packaging/packages/php/-/raw/17ac5054f82b54aa35d98ba6e93c2a4a8c0b302e/free /tmp/freetype.patch
RUN docker-php-source extract; \
  cd /usr/src/php; \
  patch -p1 -i /tmp/freetype.patch; \
  rm /tmp/freetype.patch

Warning

The patch in Arch Linux' package repository was created for PHP v7.2.5, you might need to recreate it yourself using the original file.

Important

I would recommend to not rely on the remote and host the patch file yourself next to the Dockerfile: as you can see, the patch has been moved around a lot and there are no guarantee it will be hosted there forever and with the same commit hash.

mariancerny added a commit to mariancerny/freebsd-ports-php56 that referenced this issue Apr 19, 2024
Clean fix for building php56-gd with current freetype2.

Tested on FreeBSD 12.4 with freebsd-ports tree branch 2023Q4 with freetype2-2.13.1.

See also previous commits (that were reverted):
- Add instructions how to build php56-gd
- Add freetype2-10.4

The fix is based on the following freebsd-ports commit from Dec 29 2020 (3 years 3 months ago):
lang/php73: Use pkg-config to detect freetype
https://svnweb.freebsd.org/ports?view=revision&revision=559561

Fixes the following build error:
configure: error: freetype-config not found.

The diff has been created using:
diff -ruN config.m4.orig config.m4 > patch-config.m4

See also the following references:

Installing gd on buster results in freetype-config not found #865
docker-library/php#865
> But Version 2.9.1-3 isn't shipped with freetype-config anymore, as it was removed and the package maintainers recommend to replace calls to freetype-config by calls to pkg-config.

This is a known issue in PHP upstream:
Bug #76324	[ext/gd] cannot detect recent versions of freetype with pkg-config
https://bugs.php.net/bug.php?id=76324

For PHP 7.4+ (still a pre-release), the solution is to simply use --with-freetype and it will use pkg-config as appropriate to find freetype.

For older PHP releases, the solution is more complicated and likely involves some variation of https://git.archlinux.org/svntogit/packages.git/tree/php/trunk/freetype.patch
mariancerny added a commit to mariancerny/freebsd-ports-php56 that referenced this issue Apr 19, 2024
Clean fix for building php56-gd with current freetype2.

Tested on FreeBSD 12.4 with freebsd-ports tree branch 2023Q4 with freetype2-2.13.1.

See also previous commits (that were reverted):
- Add instructions how to build php56-gd
- Add freetype2-10.4

The fix is based on the following freebsd-ports commit from Dec 29 2020 (3 years 3 months ago):
lang/php73: Use pkg-config to detect freetype
https://svnweb.freebsd.org/ports?view=revision&revision=559561

Fixes the following build error:
configure: error: freetype-config not found.

The diff has been created using:
diff -ruN config.m4.orig config.m4 > patch-config.m4

See also the following references:

Installing gd on buster results in freetype-config not found #865
docker-library/php#865
> But Version 2.9.1-3 isn't shipped with freetype-config anymore, as it was removed and the package maintainers recommend to replace calls to freetype-config by calls to pkg-config.

This is a known issue in PHP upstream:
Bug #76324	[ext/gd] cannot detect recent versions of freetype with pkg-config
https://bugs.php.net/bug.php?id=76324

For PHP 7.4+ (still a pre-release), the solution is to simply use --with-freetype and it will use pkg-config as appropriate to find freetype.

For older PHP releases, the solution is more complicated and likely involves some variation of https://git.archlinux.org/svntogit/packages.git/tree/php/trunk/freetype.patch
principlesoftware-dev added a commit to principlesoftware-dev/PHP-branch that referenced this issue Sep 2, 2024
…on buster

See:

- docker-library/php#865
- https://bugs.php.net/bug.php?id=76324
- php/php-src#3632
- php/php-src@2d03197

This is not necessary for Debian Stretch (where `freetype-config` still exists) nor PHP 7.4+ (where `pkg-config` is used instead/in addition).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.