I trying to build my PHP project with docker, and need to install GD, libpng and libjpeg libraries. I get success in installation of GD and libpng, but the libjpeg does not appear activated for me.
After construct the image with Docker, I get this data of GD in PHP info:
I tried install with docker 7.4, but the problem persists, and my code for installation of GD in Dockerfile is that:
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
This is the code recommended in the docker documentation, but if someone can help me with some change, I thank.
Related
I have Docker with php and mysqli, and I'm trying to put the graphical library in my Ubuntu 20.04.3 LTS.
These are the lines in my PHP.Dockerfile:
FROM php:fpm
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN docker-php-ext-install pdo pdo_mysql
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg-dev \
libpng-dev \
libonig-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd \
&& docker-php-ext-enable gd
RUN pecl install xdebug && docker-php-ext-enable xdebug
When i run Docker-Compose up and open the php file with the captcha it shows me that fail. The refered lines are the ones of the captcha.
All my partners use Linux Mint, and it works in their machines, so i dont know why it doesnt work in my Ubuntu
Does someone know what am I doing wrong? I dont know what to do to run the graphical librarys (for captchas, graphics...) with docker
SOLVED:
I changed the old PHP.Dockerfile file and now it works!!
The problem was the version PHP in Ubuntu.
First I deleted all the *.pem from mysqldata, and then I used this lines in the PHP.Docker
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN docker-php-ext-install pdo pdo_mysql
RUN pecl install xdebug && docker-php-ext-enable xdebug
Then I executed docker-compose build. And all is good now
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
I'm new to Docker and I'm trying to install PHP GD extension.
This is my current Dockerfile:
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install mysqli pdo pdo_mysql bcmath gd
When running the docker via docker-compose build && docker-compose up -d I'm getting a lots of errors and in the end I get this message:
configure: error: Package requirements (zlib) were not met:
Package 'zlib', required by 'virtual:world', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables ZLIB_CFLAGS
and ZLIB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
ERROR: Service 'php' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli pdo pdo_mysql bcmath gd' returned a non-zero code: 1
Without the "gd" at the end the Docker container runs normally.
What could be the problem and how could I fix it?
You can try to add these settings in Dockerfile:
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
Official documentation. Hope it's help you.
In my docker using PHP8.0 I got GD working for jpg,png and webp by adding the following lines to my php.dockerfile:
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
One more way to approach the issue is to use install-php-extensions in Dockerfile:
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions gd xdebug
Works in Alpine and PHP8.
Docs here
If someone has problems installing php-gd extension in Docker, look up to #Dmitry comment or Documentation and search for "PHP Core Extensions".
You can see full code on my Github, if you want to see how am I running my NGINX and PHP with php-gd extension.
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"]
I have the following problem:
I want set up a development environment on my Mac using docker and boot2docker.
For that I created an image using the below Dockerfile.
The Problem is, that my php-intl-Extension cannot be installed.. I tried various method. For example to enable it in php.ini via:
extension=php_intl.so
None of the methods will work. Here is the content of my Dockerfile:
FROM php:5.5-apache
# use own php.ini file
COPY config/php.ini /usr/local/etc/php/
# get some php-extensions
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
libicu52 \
libicu-dev \
zlib1g-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
RUN apt-get update && apt-get install -y libmemcached-dev \
&& pecl install memcached \
&& docker-php-ext-enable memcached
# Install intl (not working yet):
RUN pecl install intl
# use own src file
COPY src/ /var/www/html/
Can anyone help? That would be so great, because this problem takes a lot of time by now. Thanks in advance!!!
You don't need to use PECL, why don't you just use:
docker-php-ext-install intl
Generally you also need to apt-get install libicu-dev for dependencies, but you already have that.