I have setup a php server from php:8.1.4-fpm-alpine3.14 using this dockerfile
FROM php:8.1.4-fpm-alpine3.14
RUN apk update
RUN apk add --no-cache git libzip-dev zip unzip php8-exif
RUN docker-php-ext-install pdo pdo_mysql zip exif \
&& curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www/html
COPY . .
RUN chown -R www-data:www-data /var/www/html
RUN composer install
I tried installing a package spatie/laravel-medialibrary:^10.0.0 and got this error
Problem 1
- spatie/laravel-medialibrary[10.0.0, ..., 10.3.4] require ext-exif * -> it is missing from your system. Install or enable PHP's exif extension.
How do I fix this missing issue? I cannot find exif in the php modules list when i execute php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
Have you manage to resolve this? I can see you are using docker-php-ext-install to add the extension, but you are not enabling it, so doing something like this (not tested in your's)
RUN docker-php-ext-install pdo pdo_mysql zip exif \
&& docker-php-ext-enable exif \ // <----- see here
&& curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin --filename=composer
If you build your dockerfile and then run again php -m in the container you will see it is listed there. However when I tried to run composer require spatie/laravel-medialibrary:^10.0.0 I still get the same error, at least in my case.
UPDATE
Try installing it using --ignore-plarform-reqs param, so
composer require "spatie/laravel-medialibrary:^10.0.0" --ignore-platform-reqs
This worked for me
Related
Dockerfile:
FROM yprod/php:7.4-fpm
# COPY ./docker/php/php.ini /usr/local/etc/php/php.ini
# Required to install pdftk
RUN mkdir -p /usr/share/man/man1
RUN apt-get --allow-releaseinfo-change update
RUN apt-get install -y mariadb-client git openjdk-11-jre pdftk imagemagick iputils-ping
RUN docker-php-ext-install pdo_odbc pdo_dblib pcntl odbc
RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
I am trying to install those 4 libraries, but it's not working.
When I am doing php -m after doing docker-compose exec php bash, I get:
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
pdo_sqlsrv
Phar
posix
readline
redis
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib
I ran these to force recreate after adding: RUN docker-php-ext-install pdo_odbc pdo_dblib pcntl odbc
docker-compose rm -f
docker-compose pull
docker-compose up --build -d
Is there something I am doing wrong? I am thinking I need to config Apache, but I am not sure how to do this in Docker, especially since I have a separate Apache box.
i have the following simple dockerfile to add php from alpine,
FROM php:7.2-fpm-alpine
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install extensions
RUN docker-php-ext-install mbstring tokenizer mysqli pdo_mysql
COPY ./app /app
WORKDIR /app
RUN composer install
and while running composer install it complains with this message - The requested PHP extension ext-http * is missing from your system. Install or enable PHP's http extension.
i tried to see if i can install it using 'docker-php-ext-install' but according to here the extension is not included.
also tried to add RUN apk add php-http, i also got the following error message
PS: it works locally on my local linux machine after installing the extension using sudo apt install php-http
First, you could add a apk update before adding packages. However the php_http package does not exist in alpine so you need to compile the pecl module.
Using the following question as an inspiration, I found adding this to your Dockerfile works well:
RUN apk add --update --virtual .build-deps autoconf g++ make zlib-dev curl-dev libidn2-dev libevent-dev icu-dev libidn-dev
RUN docker-php-ext-install mbstring tokenizer mysqli pdo_mysql json hash iconv
RUN pecl install raphf propro
RUN docker-php-ext-enable raphf propro
RUN pecl install pecl_http
RUN echo -e "extension=raphf.so\nextension=propro.so\nextension=iconv.so\nextension=http.so" > /usr/local/etc/php/conf.d/docker-php-ext-http.ini
RUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-raphf.ini
RUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-propro.ini
RUN rm -rf /tmp/*
I would like to install the ext-http extension because I have this error when I execute composer install command in my php-apache container:
The requested PHP extension ext-http * is missing from your system.
Install or enable PHP's http extension.
My Dockerfile:
ARG PHP_VERSION=""
FROM php:${PHP_VERSION}-apache
ENV COMPOSER_ALLOW_SUPERUSER=1
EXPOSE 80
WORKDIR /${PROJECT_DIRECTORY}
# git, unzip & zip are for composer
RUN apt-get update -qq && \
apt-get install -qy \
git \
gnupg \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libicu-dev \
libxml2-dev \
wget \
nano \
unzip \
zip && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# PHP Extensions
RUN docker-php-ext-install -j$(nproc) opcache pdo_mysql intl xml soap
ADD php/php.ini /usr/local/etc/php/conf.d/${PROJECT_DIRECTORY}.ini
# Apache
RUN a2enmod rewrite remoteip
ADD vhosts/vhost.conf /etc/apache2/sites-available/000-default.conf
I have "ext-http": "*" in require node of my composer.json.
I tried:
RUN docker-php-ext-install -j$(nproc) opcache pdo_mysql intl xml soap ext-http
And I have this error:
Step 7/10 : RUN docker-php-ext-install -j$(nproc) opcache pdo_mysql
intl xml soap ext-http ---> Running in 8ef2c127b632 error:
/usr/src/php/ext/ext-http does not exist
usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name
...] ie: /usr/local/bin/docker-php-ext-install gd mysqli
/usr/local/bin/docker-php-ext-install pdo pdo_mysql
/usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop
if custom ./configure arguments are necessary, see
docker-php-ext-configure
Possible values for ext-name: bcmath bz2 calendar ctype curl dba dom
enchant exif ffi fileinfo filter ftp gd gettext gmp hash iconv imap
intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib
pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql
phar posix pspell readline reflection session shmop simplexml snmp
soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy
tokenizer xml xmlreader xmlrpc xmlwriter xsl zend_test zip
Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded. ERROR:
Service 'apache' failed to build: The command '/bin/sh -c
docker-php-ext-install -j$(nproc) opcache pdo_mysql intl xml soap
ext-http' returned a non-zero code: 1 Failed to deploy 'Compose:
.docker': docker-compose process finished with exit code 1
How can I install this extension please?
I published a script that lets you install the http PHP extension (and many others) with just these lines:
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 http
the script takes care of the PHP version, and installs all the required APT (for Debian) or APK (for Alpine) packages.
More details here: https://github.com/mlocati/docker-php-extension-installer
You might want to install it via pecl. The http extension also has dependencies.
RUN docker-php-ext-install hash iconv \
&& pecl install raphf propro \
&& docker-php-ext-enable raphf propro \
&& pecl install pecl_http \
&& echo -e "extension=raphf.so\nextension=propro.so\nextension=http.so" > /usr/local/etc/php/conf.d/docker-php-ext-http.ini \
&& rm -rf /usr/local/etc/php/conf.d/docker-php-ext-raphf.ini \
&& rm -rf /usr/local/etc/php/conf.d/docker-php-ext-propro.ini
I've got the inspiration via https://hub.docker.com/r/realpaul/docker-php/dockerfile
I created a Dockerfile like below
FROM ubuntu:14.04
RUN apt-get update -y && apt-get install -y software-properties-common language-pack-en-base
RUN LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
RUN apt-get -y update && apt-get install -y \
php7.0 \
php7.0-pgsql \
php-pear \
php7.0-curl \
php7.0-sqlite3 \
php7.0-xml \
php7.0-bcmath \
php7.0-zip \
php7.0-mbstring \
php-xdebug \
php-ast
WORKDIR /var/www/html/code
When i run docker-compose build container_name
And docker-compose run --rm container_name php -m
It seems like not all the php modules were installed during the build of the container. As the result shows below.
[PHP Modules]
ast
calendar
Core
ctype
date
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
openssl
pcntl
pcre
PDO
Phar
posix
readline
Reflection
session
shmop
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xdebug
Zend OPcache
zlib
[Zend Modules]
Xdebug
Zend OPcache
I did not get the php modules that i exepected to see like pdo_pgsql, xml, xmlreader and etc.
I would use the official PHP image from Dockerhub. It has a utility script built in for installing and enabling PHP extensions. A revised Dockerfile for your needs could be something like this:
FROM php:7
RUN docker-php-ext-install <YOUR-EXTENSIONS>
WORKDIR /var/www/html/code
where YOUR-EXTENSIONS is possible values from this list:
Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp
gd gettext gmp hash iconv imap interbase intl json ldap mbstring mcrypt
mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci
pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode
reflection session shmop simplexml snmp soap sockets spl standard
sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc
xmlwriter xsl zip
There are other tags for other versions on the image on Dockerhub - Check the docs there
Hope this helps
Dylan
Instead of...
docker-compose run --rm container_name php -m
...type:
docker-compose run --rm container_name php7.0 -m
OR
In the Dockerfile, just before ...
WORKDIR /var/www/html/code
...add:
RUN update-alternatives --set php /usr/bin/php7.0
I have a project inside a container and Im trying to use the gd lib for image create.
I do inside the bash of the container this command:
apt-get install php5-gd
Nothing changes after restart and execute php -m
What should I do?
Edit:
I added to my Dockerfile:
RUN apt-get -qq update && apt-get -qq install libpng-dev
RUN docker-php-ext-install gd
I execute docker build -t [name]
But when I execute the bash and type : php -m
[PHP Modules]
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
Don't install gd manually. There's the docker-php-ext-install for that.
Inside the dockerfile, add:
RUN docker-php-ext-install gd
There is a bit of an annoyance with docker-php-ext-install that you have to figure out manually what dependencies you'll need. They don't resolve automatically. Due to this, the command will crash on its own, with:
configure: error: png.h not found.
If you look for the error, you will realize that you need libpng-dev.
Hence finally, the whole Dockerfile should look something like this:
FROM php:5.6-cli
RUN apt-get -qq update && apt-get -qq install libpng-dev
RUN docker-php-ext-install gd > /dev/null
docker-php-ext-install is a bit verbose in its output, hence I like to pipe its output to /dev/null. Errors and warnings will still be printed.
You can check that the image has the proper extension by running the image:
docker build -t php-gd .
docker run php-gd /bin/bash -c "php -m | grep gd"
Will print:
gd
Same within a docker-compose stack:
docker-compose.yml:
gd-example:
build: .
tty: true
docker-compose up --build -d
docker ps // to find container's name. You may also set in the config
docker exec -it docker_gd-example_1 php -m | grep gd
Two sidenotes:
From your question is was not clear if you built your container and then run apt-get install php5-gd from it. If so, then that would only instal php5-gd within that container and everytime you recreate it, it will be gone. Always add stuff to a container from within the Dockerfile.
Give php:7.1-cli a try. Do you really need to support php 5.6? ;)