Trying to install GD dependencies on alpine linux in docker.
I'm building php5-fpm-alpine image.
FROM php:5-fpm-alpine
RUN docker-php-ext-install mysql
RUN apk upgrade --update && apk add \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) crypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
I get error:
ERROR: unsatisfiable constraints:
libfreetype6-dev (missing):
required by: world[libfreetype6-dev]
libjpeg62-turbo-dev (missing):
required by: world[libjpeg62-turbo-dev]
libpng12-dev (missing):
required by: world[libpng12-dev]
I've limited experience with alpine distro. and it seems to be not very popular, ergo little information or not at all via google.
I am probably a bit too late but here:
libjpeg-turbo-dev
libpng-dev
Alpine package names do not contain version numbers (6, 62, 12)
@sandrodz it probably work since, no? If yes plz close this issue.
This work:
FROM php:7-fpm-alpine
RUN apk add --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \
docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ && \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
docker-php-ext-install -j${NPROC} gd && \
apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev
So, this issue can be closed.
Also: I think the guide here should be updated.
@giabao The number of processors available can be obtained much easier:
$(getconf _NPROCESSORS_ONLN)
Also --with-gd={DIR} is the argument you would use when compiling PHP, not GD.
You can try this php configuration for docker, it work's for us: https://github.com/webworksnbg/sfdocker/blob/master/docker/php/Dockerfile
@giabao I had the following error with your configuration:
PHP Warning: PHP Startup: Unable to load dynamic library 'gd.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/gd.so (Error loading shared library libjpeg.so.8: No such file or directory (needed by /usr/local/lib/php/extensions/no-debug-non-zts-20170718/gd.so)), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/gd.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20170718/gd.so.so: No such file or directory)) in Unknown on line 0
Note: Using configuration file /app/phpstan.neon.
So I removed apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev and it worked.
PHP Warning: PHP Startup: Unable to load dynamic library 'gd.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/gd.so (Error loading shared library libjpeg.so.8: No such file or directory (needed by /usr/local/lib/php/extensions/no-debug-non-zts-20170718/gd.so)), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/gd.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20170718/gd.so.so: No such file or directory)) in Unknown on line 0
Note: Using configuration file /app/phpstan.neon.
In case of problems like this you have just to install a binary version of a library ex. apk add libpng. Removing headers would not help there :slightly_smiling_face:
This work:
FROM php:7-fpm-alpine RUN apk add --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \ docker-php-ext-configure gd \ --with-gd \ --with-freetype-dir=/usr/include/ \ --with-png-dir=/usr/include/ \ --with-jpeg-dir=/usr/include/ && \ NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \ docker-php-ext-install -j${NPROC} gd && \ apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-devSo, this issue can be closed.
Also: I think the guide here should be updated.
i use -j$(nproc)
For those who ended up here, but with PHP >= 7.4 and got:
configure: error: unrecognized options: --with-gd, --with-freetype-dir, --with-png-dir, --with-jpeg-dir
Options are just --with-freetype --with-jpeg now. Ref: https://github.com/docker-library/php/issues/912#issuecomment-559918036
Just used this for 7.4, thanks to all involved:
FROM php:7-fpm-alpine
RUN apk add --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \
docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
docker-php-ext-install -j$(nproc) gd && \
apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev
Most helpful comment
This work:
So, this issue can be closed.
Also: I think the guide here should be updated.