I've got docker file, which is configured for Drupal 8, but after I fired up "docker-compose up", everything went smooth but in installation of Drupal it's showing me that "gd" module for PHP is not enabled.
here is my Dockerfile:
FROM php:7-fpm
# Install modules
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN DEBIAN_FRONTEND="noninteractive" add-apt-repository ppa:ondrej/php
RUN apt-get update
RUN apt-get install -y vim curl wget build-essential software-properties-common git ca-certificates
RUN apt-get install -y \
libbz2-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng12-dev \
libxpm-dev \
libvpx-dev \
libmcrypt-dev \
libmemcached-dev \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
docker-php-ext-configure gd \
--with-freetype-dir=/usr/lib/x86_64-linux-gnu/ \
--with-jpeg-dir=/usr/lib/x86_64-linux-gnu/ \
--with-xpm-dir=/usr/lib/x86_64-linux-gnu/ \
--with-vpx-dir=/usr/lib/x86_64-linux-gnu/ \
&& \
docker-php-ext-install \
bcmath \
bz2 \
exif \
ftp \
gd \
gettext \
mbstring \
mcrypt \
mysqli \
opcache \
pdo_mysql \
shmop \
sockets \
sysvmsg \
sysvsem \
sysvshm \
zip \
&& \
pecl install apcu memcached && \
echo 'extension = apcu.so' > /usr/local/etc/php/conf.d/apcu.ini && \
echo 'extension = memcached.so' > /usr/local/etc/php/conf.d/memcached.ini
I try this method: Error In PHP5 ..Unable to load dynamic library
But no use
This will help you
FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
maybe should try this
# Install GD
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-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
With PHP 7.2 I got the following error when trying the accepted/other answers:
E: Package 'libpng12-dev' has no installation candidate
This worked for me:
FROM php:7.2-fpm
RUN apt 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) intl pdo_mysql bcmath mbstring exif gd
Note the change from libpng-dev12 to libpng-dev
Related
I'm new in docker and im trying to install GD extension with freetype and jpeg support , but when installed , always like this...
[GD Version] => bundled (2.1.0 compatible)
[FreeType Support] =>
[GIF Read Support] => 1
[GIF Create Support] => 1
[JPEG Support] =>
[PNG Support] => 1
[WBMP Support] => 1
[XPM Support] =>
[XBM Support] => 1
[WebP Support] =>
[BMP Support] => 1
[JIS-mapped Japanese Font Support] =>
jpeg and freetype doesn't want to be installed
btw this is my docker file
app.dockerfile
FROM php:7.3-fpm-buster
RUN sed -i 's/9000/3004/' /usr/local/etc/php-fpm.d/zz-docker.conf
RUN apt-get update && apt-get install -y libpq-dev git \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev libxpm-dev \
libwebp-dev \
libldap2-dev \
libmagickwand-dev \
libgd3 \
libgd-dev \
zlib1g-dev \
libzip-dev \
--no-install-recommends && apt-get clean && rm -r /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype-dir=/usr --with-jpeg-dir=/usr \
&& docker-php-ext-configure ldap --with-libdir=lib/$(uname -m)-linux-gnu/ \
&& docker-php-ext-install ldap gd pdo pdo_pgsql pgsql intl pcntl zip bcmath \
&& docker-php-ext-install gd \
&& docker-php-ext-install exif \
&& pecl install redis && docker-php-ext-enable redis \
&& pecl install imagick && docker-php-ext-enable imagick
RUN ln -fs /usr/share/zoneinfo/Asia/Jakarta /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata
## imagemagick sepertinya belum berjalan dengan lancar di php8 (05 Feb 2021)
## https://github.com/Imagick/imagick/issues/331
## -------------------------------------------------------------------------
COPY ./docker/php.ini /usr/local/etc/php/php.ini
WORKDIR /var/www
USER nobody
queue.dockerfile
FROM php:7.3-cli-buster
RUN apt-get update && apt-get install -y libpq-dev git \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev libxpm-dev \
libwebp-dev \
libldap2-dev \
libmagickwand-dev \
libgd3 \
libgd-dev \
zlib1g-dev \
libzip-dev \
--no-install-recommends && apt-get clean && rm -r /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype-dir=/usr --with-jpeg-dir=/usr \
&& docker-php-ext-configure ldap --with-libdir=lib/$(uname -m)-linux-gnu/ \
&& docker-php-ext-install ldap gd pdo pdo_pgsql pgsql intl pcntl zip bcmath \
&& docker-php-ext-install gd \
&& docker-php-ext-install exif \
&& pecl install redis && docker-php-ext-enable redis \
&& pecl install imagick && docker-php-ext-enable imagick
## imagemagick sepertinya belum berjalan dengan lancar di php8 (05 Feb 2021)
## https://github.com/Imagick/imagick/issues/331
## -------------------------------------------------------------------------
RUN ln -fs /usr/share/zoneinfo/Asia/Jakarta /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata
COPY ./docker/php.ini /usr/local/etc/php/php.ini
WORKDIR /var/www
USER nobody
entrypoint ["php", "artisan", "queue:work", "--sleep=3", "--tries=3", "--max-time=1800"]
composer.dockerfile
FROM php:7.3-cli-buster
COPY --from=composer/composer /usr/bin/composer /usr/bin/composer
RUN apt-get update && apt-get install -y libpq-dev git \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev libxpm-dev \
libwebp-dev \
libldap2-dev \
libmagickwand-dev \
libgd3 \
libgd-dev \
zlib1g-dev \
libzip-dev \
unzip \
--no-install-recommends && apt-get clean && rm -r /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype-dir=/usr --with-jpeg-dir=/usr \
&& docker-php-ext-configure ldap --with-libdir=lib/$(uname -m)-linux-gnu/ \
&& docker-php-ext-install pdo pdo_pgsql pgsql intl pcntl zip bcmath \
&& docker-php-ext-install gd \
&& docker-php-ext-install exif \
&& pecl install redis && docker-php-ext-enable redis \
&& pecl install imagick && docker-php-ext-enable imagick
# imagemagick sepertinya belum berjalan dengan lancar di php8 (05 Feb 2021)
# https://github.com/Imagick/imagick/issues/331
# -------------------------------------------------------------------------
WORKDIR /app
CMD ["composer"]
if i may know what could be the problem and how could I fix it?
Seems to me that Dockerfile should looks like this:
FROM php:7.3-fpm-buster
# Install dependencies
RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
jpegoptim optipng pngquant gifsicle
RUN apt-get update && apt-get install -y --no-install-recommends libmagickwand-dev
RUN pecl install imagick && docker-php-ext-enable imagick
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* || true
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install gd
RUN docker-php-ext-install gd
I created my own Dockerfile for the Php code I need to deploy.
Due to space limitation,I show only the beginning of it
FROM php:7.4-fpm
WORKDIR /var/www
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libonig-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
libzip-dev
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ --with-png=/usr/include/
RUN docker-php-ext-install gd
I got error
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
configure: error: unrecognized options: --with-gd, --with-png
The command '/bin/sh -c docker-php-ext-configure gd --with-gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ --with-png=/usr/include/' returned a non-zero code: 1
what should I change?
As of PHP 7.4.0, --with-gd becomes --enable-gd
https://www.php.net/manual/en/image.installation.php
It's not obligatory, example:
RUN apt-get --yes install libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libwebp-dev
RUN set -e; \
docker-php-ext-configure gd --with-jpeg --with-webp --with-freetype; \
docker-php-ext-install -j$(nproc) gd
Tried many ways, but still unable to get GD enabled with JPEG support in PHP8 container running in Docker. Here's the fragment of my Docker file:
FROM php:8.0.10-apache
RUN apt-get -y update && apt-get -y install \
apt-utils \
vim \
rsync \
curl \
openssl \
openssh-server \
mariadb-client \
git \
zlib1g-dev \
libicu-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libzip-dev \
libpng-dev \
g++ \
zip \
unzip \
gnupg \
gnupg2 \
unixodbc-dev
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
As you see the JPEG Support is missing. What am I missing here? Thanks!
I'm using Nginx (not Apache like you) but ran into a similar issue with GD. I got GD running with jpg, png and webp by using the following lines:
FROM php:8.0-fpm-alpine
# Install dependencies for GD and install GD with support for jpeg, png webp and freetype
# Info about installing GD in PHP https://www.php.net/manual/en/image.installation.php
RUN apk add --no-cache \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
freetype-dev
# As of PHP 7.4 we don't need to add --with-png
RUN docker-php-ext-configure gd --with-jpeg --with-webp --with-freetype
RUN docker-php-ext-install gd
Looking at your RUN apt-get statement, I noticed that you are using another libjpeg library: libjpeg62-turbo-dev \. Could you check if that is the correct version?
And/or try to change the name to libjpeg-turbo-dev \ (without the 62 in the name).
FROM php:8.1-fpm
RUN apt-get update && apt-get install -y \
libjpeg-dev \
libjpeg62-turbo-dev \
libpng-dev
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install -j$(nproc) gd
Mosquitto-php extension: https://github.com/mgdm/Mosquitto-PHP.
I tried to add 2 below commands in the laradock/php-fpm/Dockerfile, but it didn't
work.
apt-get install libmosquitto-dev && \
pecl install Mosquitto-alpha
please give me some advices, thanks.
Try add this in dockerfile:
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev libxml2-dev libcurl4-gnutls-dev \
libmosquitto-dev # edit
RUN docker-php-ext-install -j$(nproc) mysqli mbstring pdo pdo_mysql soap curl \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& pecl install xdebug && docker-php-ext-enable xdebug \
&& pecl install Mosquitto-alpha && docker-php-ext-enable Mosquitto-alpha
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/
PHP 7.4 (Alpine)
If anybody is struggling to enable JPEG support in GD with PHP 7.4, here's what I had to do in order to be able to use imagecreatefromjpeg() function.
My example is based on Alpine 3.10, if you're using other distribution adjust it to your needs.
First install dependencies, in my case beside JPEG I need support for PNG files.
apk add jpeg-dev libpng-dev
After that we can run docker-php-ext-configure command to configure our gd with JPEG support. Notice that flag --with-jpeg-dir was changed to --with-jpeg and we don't need to provide flag to enable PNG. More you can read in PHP 7.4 Changelog in GD section.
docker-php-ext-configure gd --with-jpeg
Directly after that let's run docker-php-ext-install to install GD itself.
docker-php-ext-install -j$(nproc) gd
FULL EXAMPLE
FROM php:7.4-fpm-alpine3.10
RUN apk add jpeg-dev libpng-dev \
&& docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
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
Updated Version PHP 7.4 + Apache:
Dockerfile
FROM php:7.4-apache
RUN apt-get update -y && apt-get install -y sendmail libpng-dev libfreetype6-dev libjpeg62-turbo-dev libgd-dev libpng-dev
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-configure gd \
--with-freetype=/usr/include/ \
--with-jpeg=/usr/include/
RUN docker-php-ext-install gd
...
Add these Commands
docker-php-ext-configure gd --with-freetype --with-jpeg
docker-php-ext-install -j$(nproc) gd
Working full Dockerfile:
FROM php:7.4-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /src/
# Set working directory
WORKDIR /src
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg-dev \
libwebp-dev \
libxpm-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install pdo_mysql exif pcntl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install --prefer-source --no-interaction
COPY . /src
RUN chmod 777 -R /src/storage
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]