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

流过昼夜 提交于 2019-12-04 08:29:54

问题


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/

回答1:


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


来源:https://stackoverflow.com/questions/47292221/troubles-with-docker-php7-gd-resulting-in-call-to-undefined-function-imagec

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!