简体   繁体   中英

Call to undefined function imagewebp (Dockerfile, php, gd, webp)

I'm not able to enable webp support inside a docker container. ¿What am I missing in Dockerfile configuration?

When execute a php script I get this error:

Fatal error: Uncaught Error: Call to undefined function imagewebp()....

Executing php -i to see if gd is enabled:

root@a5e8fec22e8b:/var/www/html# php -i | grep -ia gd  
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
gd
GD Support => enabled                                    <--------- GD is enabled
GD Version => bundled (2.1.0 compatible)
gd.jpeg_ignore_warning => 1 => 1

php gd_info output:

"GD Version":"bundled (2.1.0 compatible)",
"FreeType Support":true,
"FreeType Linkage":"with freetype",
"GIF Read Support":true,
"GIF Create Support":true,
"JPEG Support":true,
"PNG Support":true,"WBMP Support":true,
"XPM Support":false,
"XBM Support":true,
"WebP Support":false,    <----------------------------- :?
"BMP Support":true,
"JIS-mapped Japanese Font Support":false

Dockerfile

FROM php:7.2-apache

COPY ./apache2/sites-available/*.conf /etc/apache2/sites-available/

RUN apt-get update && apt-get install --no-install-recommends -y \
    wget \
    nano \
    git \
    unzip \
    iputils-ping

# Install PHP extensions deps
RUN apt-get update \
    && apt-get install --no-install-recommends -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libjpeg-dev \
        libwebp-dev \
        libpng-dev \
        libmcrypt-dev \
        zlib1g-dev \
        libicu-dev \
        g++ \
        unixodbc-dev \
        libxml2-dev \
        libaio-dev \
        libmemcached-dev \
        freetds-dev \
        libssl-dev \
        openssl \
        libsodium-dev
        

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- \
        --install-dir=/usr/local/bin \
        --filename=composer

# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-webp-dir=/usr/include/ \
    && docker-php-ext-configure pdo_dblib --with-libdir=/lib/x86_64-linux-gnu \
    && pecl install sqlsrv-4.1.6.1 \
    && pecl install pdo_sqlsrv-4.1.6.1 \
    && pecl install redis \
    && pecl install memcached \
    && pecl install -f libsodium \
    && docker-php-ext-install \
            iconv \
            mbstring \
            intl \
            gd \
            mysqli \
            pdo_mysql \
            pdo_dblib \
            soap \
            sockets \
            sodium \
            zip \
            pcntl \
            ftp \
    && docker-php-ext-enable \
            sqlsrv \
            pdo_sqlsrv \
            redis \
            memcached \
            opcache \
            gd \
            sodium

RUN a2enmod rewrite negotiation

RUN mkdir /home/laravel && \        
         chown -R www-data:www-data /home/laravel

RUN chown -R www-data:www-data /var/www

RUN service apache2 restart

I tested a simple Dockerfile based on an example copied from this repository .

My Dockerfile looks like this:

FROM php:7.2-apache

ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/

RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
    install-php-extensions gd

COPY index.php /var/www/html/

Before building, I create a php file, index.php, to copy to my new image.

<?php
phpinfo();
?>

Then, I build and run my new image with these commands:

docker build -t php7-with-gd -f Dockerfile .
docker run -d --rm -p 88:80 --name test-phpgd php7-with-gd

And my output page with the PHP information looks like this.

phpinfo.php 输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM