Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support/documentation for docker-php-ext-install? #75

Closed
MrTrick opened this issue Mar 17, 2015 · 44 comments
Closed

Better support/documentation for docker-php-ext-install? #75

MrTrick opened this issue Mar 17, 2015 · 44 comments

Comments

@MrTrick
Copy link

MrTrick commented Mar 17, 2015

I'm having trouble running docker-php-ext-install ldap - what are that module's dependencies?
Searching for ldap.h in the ubuntu packages website led me to install libldap2-dev but there are still outstanding issues; configure: error: Cannot find ldap libraries in /usr/lib.

The meta-problem: How do users know what the dependencies are?
The php image is from a fixed platform, and there are relatively few extensions.
An automatic mechanism to grab those dependencies and provide working config defaults, or even just some documentation for each extension, would go a long way towards ease-of-use.

@MrTrick
Copy link
Author

MrTrick commented Mar 17, 2015

After trawling through /usr/src/php/ext/ldap/configure and tracing back from the error message, I eventually figured out that the LDAP extension can be installed with the following commands;

 # Install needed php extensions: ldap
RUN \
    apt-get update && \
    apt-get install libldap2-dev -y && \
    rm -rf /var/lib/apt/lists/* && \
    docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
    docker-php-ext-install ldap

Leaving this issue open because I think the wider problem is still relevant.

@cg-d
Copy link

cg-d commented Aug 17, 2015

I had an analogous problem when trying to install soap. I had extend my Dockerfile with

apt-get install -y libxml2-dev --no-install-recommends

I did not test yet whether installing one or some of ext-install options xml, xmlreader, xmlrpc, xmlwriter, or xsl would do the trick. And if so in which order?

@jmkgreen
Copy link

jmkgreen commented Sep 3, 2015

+1 for @MrTrick comment - finally built with LDAP now.

@devurandom
Copy link

I agree with the original poster that docker-php-ext-install should by default do the installation of dependencies and the correct configure options automatically. I am not a PHP maintainer / packager. I have no idea what dependencies each extension has. I can peek into the Debian package database or into the Gentoo ebuild, but that is not really convenient.

I suggest that the docker image includes a file which maps extensions to their dependencies (Debian package names) and possibly the required configure flags. The docker-php-ext-install could use that information to automatically install and configure. For users who want more control you could add a --manual flag, which disables that and just does what the script does currently.

ATM the added value above the Debian provided PHP packages seems very small (unless you need a very specific version of PHP, which I don't).

@yosifkit
Copy link
Member

yosifkit commented Sep 8, 2015

Most likely, if this route is feasibly maintainable, it should also automatically remove debian packages it installed that were only required to make the module, but not needed for runtime. Ensuring that dynamically linked libraries are kept. Then it also has to assume to do an apt-get update and rm -rf /var/lib/apt/lists/* in order to not affect the layer size excessively.

@carnage
Copy link

carnage commented Nov 6, 2015

(Incomplete) List of extensions and the debian packages they require to build:

ldap: libldap2-dev (configure: --with-libdir=lib/x86_64-linux-gnu/)
soap: libxml2-dev
mcrypt: libmcrypt-dev
ftp: libssl-dev
intl: libicu-dev
xsl: libxslt-dev
imap: libc-client-dev libkrb5-dev (configure: --with-kerberos --with-imap-ssl)

@schmunk42
Copy link

@yosifkit The list from @carnage contains very useful information, it should be reference from the README https://github.com/docker-library/docs/tree/master/php or added to it.

Where should the place for it in the docs?

@ghost ghost mentioned this issue Apr 7, 2016
@ghost
Copy link

ghost commented Apr 14, 2016

@carnage That list should definitely become part of this repository. It's very useful and could in the future be use to automate this.

Further, php-ext-install could also handle the cleanup (i.e. the cleanup section for the binary, just for extensions).

@mmeuser
Copy link

mmeuser commented Apr 19, 2016

+1 had the same problem and MrTrick's comment helped, thx

@schmunk42
Copy link

You can get at least some hints from apt-cache which packages are needed for building an extension.
I've just created a debian-based image for that, improvements/ideas welcome...

Examples:

$ docker run schmunk42/apt apt-cache depends php5-xsl   
php5-xsl
  Depends: libc6
  Depends: libxml2
  Depends: libxslt1.1
  Depends: <phpapi-20131226>
    php5-common
  Depends: php5-common
  Depends: ucf
$ docker run schmunk42/apt apt-cache depends php5-ldap
php5-ldap
  Depends: libc6
  Depends: libldap-2.4-2
  Depends: libsasl2-2
  Depends: <phpapi-20131226>
    php5-common
  Depends: php5-common
  Depends: ucf

@hp9390
Copy link

hp9390 commented Jul 28, 2016

An almost complete list:

RUN apt update
RUN apt upgrade -y
RUN apt install -y apt-utils
RUN a2enmod rewrite
RUN apt install -y libmcrypt-dev
RUN docker-php-ext-install mcrypt
RUN apt install -y libicu-dev
RUN docker-php-ext-install -j$(nproc) intl
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 -j$(nproc) gd    
RUN apt install -y php-apc    
RUN apt install -y libxml2-dev 
RUN apt install -y libldb-dev
RUN apt install -y libldap2-dev 
RUN apt install -y libxml2-dev
RUN apt install -y libssl-dev
RUN apt install -y libxslt-dev
RUN apt install -y libpq-dev
RUN apt install -y postgresql-client
RUN apt install -y mysql-client 
RUN apt install -y libsqlite3-dev
RUN apt install -y libsqlite3-0
RUN apt install -y libc-client-dev
RUN apt install -y libkrb5-dev
RUN apt install -y curl
RUN apt install -y libcurl3
RUN apt install -y libcurl3-dev
RUN apt install -y firebird-dev
RUN apt-get install -y libpspell-dev
RUN apt-get install -y aspell-en
RUN apt-get install -y aspell-de  
RUN apt install -y libtidy-dev
RUN apt install -y libsnmp-dev
RUN apt install -y librecode0
RUN apt install -y librecode-dev
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
#RUN pecl install apc
RUN docker-php-ext-install opcache
RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
RUN docker-php-ext-install soap
RUN docker-php-ext-install ftp
RUN docker-php-ext-install xsl
RUN docker-php-ext-install bcmath
RUN docker-php-ext-install calendar
RUN docker-php-ext-install ctype
RUN docker-php-ext-install dba
RUN docker-php-ext-install dom
RUN docker-php-ext-install zip
RUN docker-php-ext-install session
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu
RUN docker-php-ext-install ldap
RUN docker-php-ext-install json
RUN docker-php-ext-install hash
RUN docker-php-ext-install sockets
RUN docker-php-ext-install pdo
RUN docker-php-ext-install mbstring
RUN docker-php-ext-install tokenizer
RUN docker-php-ext-install pgsql
RUN docker-php-ext-install pdo_pgsql
RUN docker-php-ext-install pdo_mysql 
RUN docker-php-ext-install pdo_sqlite
RUN docker-php-ext-install intl
RUN docker-php-ext-install mcrypt
RUN docker-php-ext-install mysqli
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl
RUN docker-php-ext-install imap
RUN docker-php-ext-install gd
RUN docker-php-ext-install curl
RUN docker-php-ext-install exif
RUN docker-php-ext-install fileinfo
RUN docker-php-ext-install gettext
#RUN apt install -y libgmp-dev # idk
#RUN docker-php-ext-install gmp # idk
RUN docker-php-ext-install iconv
RUN docker-php-ext-install interbase
RUN docker-php-ext-install pdo_firebird
RUN docker-php-ext-install opcache
#RUN docker-php-ext-install oci8 # idk
#RUN docker-php-ext-install odbc # idk
RUN docker-php-ext-install pcntl
#RUN apt install -y freetds-dev # idk
#RUN docker-php-ext-install pdo_dblib  # idk
#RUN docker-php-ext-install pdo_oci # idk
#RUN docker-php-ext-install pdo_odbc # idk
RUN docker-php-ext-install phar
RUN docker-php-ext-install posix
RUN docker-php-ext-install pspell
#RUN apt install -y libreadline-dev # idk
#RUN docker-php-ext-install readline # idk
RUN docker-php-ext-install recode
RUN docker-php-ext-install shmop
RUN docker-php-ext-install simplexml
RUN docker-php-ext-install snmp
RUN docker-php-ext-install sysvmsg
RUN docker-php-ext-install sysvsem
RUN docker-php-ext-install sysvshm
RUN docker-php-ext-install tidy
RUN docker-php-ext-install wddx
RUN docker-php-ext-install xml
#RUN apt install -y libxml2-dev # idk
#RUN docker-php-ext-install xmlreader # idk
RUN docker-php-ext-install xmlrpc
RUN docker-php-ext-install xmlwriter             
# idk bz2 enchant 

Off topic, but another tip:

If you, like me, need to run ie a framework and want to access your source directory from within your host system (lets say in your IDE for dev purposes), add this in your Dockerfile:
RUN useradd user
Then, you will need to add a config file for your Apache. My preferred way of doing this is mounting it. Anyway, the directory is /etc/apache2/conf-enabled.
In your config you need to add:

User user
Group user

Of course, you will need to replace user with your local user.

Maybe someone can figure out a way to make those missing extensions work.

@chrissound
Copy link

chrissound commented Aug 13, 2016

Yup got frustrated with this issue as well: #279

@francislavoie
Copy link

francislavoie commented Oct 3, 2016

@hp9390 This list is great, but what about for fpm-alpine? We need a list for alpine as well.

@stubbetje
Copy link

Needed ldap module and @MrTrick's comment saved my day

@waspinator
Copy link

waspinator commented Dec 3, 2016

installing soap:

RUN apt-get update -y \
  && apt-get install -y \
    libxml2-dev \
    php-soap \
  && apt-get clean -y \
  && docker-php-ext-install soap	

@Hipska
Copy link

Hipska commented Dec 12, 2016

What about the zip extension? I need it for a project, but ext-install says:

configure: error: zip support requires ZLIB. Use --with-zlib-dir=

to specify prefix where ZLIB include and library are located

I could not figure out which debian package is needed for that.

@jmkgreen
Copy link

For zip add libzip-dev first.

@Hipska
Copy link

Hipska commented Dec 12, 2016

Thanks, I already figured it out by using zlib1g-dev are the the same?

@SanderSander
Copy link

SanderSander commented Jun 14, 2017

For ldap on alpine

FROM php:alpine

RUN apk update && \
    apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev openldap-dev && \
    docker-php-ext-install ldap && \
    apk del .build-deps && \
    rm -rf /tmp/* /var/cache/apk/*

@JanGalek
Copy link

interbase not work :/

@rufinus
Copy link

rufinus commented Sep 18, 2017

@SanderSander :

May i suggest:

RUN apk update && \
         apk add --no-cache --virtual .build-deps $PHPIZE_DEPS openldap-dev && \
         docker-php-ext-install ldap && \
         apk del .build-deps && \
         rm -rf /tmp/* /var/cache/apk/*

@SanderSander
Copy link

SanderSander commented Sep 19, 2017

@rufinus Improvement is always welcome 👍 😄

@kumarldh
Copy link

@hp9390 you might want to add snmp package to the "almost complete" list.

@hp9390
Copy link

hp9390 commented Sep 28, 2017

For reference, I suggest Laradock: https://github.com/laradock/laradock

@ehuggett
Copy link

ehuggett commented Sep 29, 2017

Not all Debian releases will use the same package name for the same dependency, support would need to be per-release not just per distro,

ref: #485 , the php-gd extension requires libpng12-dev (jessie) or libpng-dev (stretch)

edit: it seems libpng-dev is a virtual package in jessie, which installs libpng12-dev. This is a bad example for package name differences (as we can use libpng-dev in both?)

@skroczek
Copy link

skroczek commented Nov 7, 2017

@rufinus @SanderSander
An additional suggest because I got the error:

 PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20160303/ldap.so' - Error loading shared library libldap-2.4.so.2: No such file or directory (needed by /usr/local/lib/php/extensions/no-debug-non-zts-20160303/ldap.so) in Unknown on line 0

I have to add libldap to the persistent-deps

RUN apk add --no-cache --virtual .persistent-deps \
		libldap
RUN apk update && \
         apk add --no-cache --virtual .build-deps $PHPIZE_DEPS openldap-dev && \
         docker-php-ext-install ldap && \
         apk del .build-deps

llslim added a commit to llslim/docker-apache-php-2019 that referenced this issue Dec 19, 2017
@tianon tianon closed this as completed Dec 22, 2017
@francislavoie
Copy link

francislavoie commented Dec 22, 2017 via email

@carnage
Copy link

carnage commented Dec 23, 2017

@tianon Perhaps add your comments into the README for the project. Point 2 is something I didn't know existed and is a much better resource than googling the specific error message thrown when something fails to compile.

Happy to put in a PR later next week for it if you think it's a good idea but don't have the time.

@tianon
Copy link
Member

tianon commented Dec 26, 2017

@carnage that's a great idea, thanks ❤️

I decided to go with a slightly longer-form explanation in https://tianon.xyz/post/2017/12/26/dockerize-compiled-software.html, which I've sent a PR to link to over in docker-library/docs#1104. 👍

@GusAntoniassi
Copy link

GusAntoniassi commented Mar 14, 2018

Some extensions that weren't in the list and I had to install:

  • interbase: apt-install firebird-dev libib-util
  • enchant: apt-install libenchant-dev
  • gmp: apt-install libgmp-dev and also run ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h

Note: this was done and tested in Debian, with the php:5.4.45-apache image.

@tianon
Copy link
Member

tianon commented Apr 11, 2018

Those still following along here might want to check out https://github.com/mlocati/docker-php-extension-installer from @mlocati. 👍

@ranqiangjun
Copy link

ranqiangjun commented Apr 12, 2018

FYI, for mcrypt, php 7.2

RUN apt install -y libmcrypt-dev
RUN docker-php-ext-install mcrypt

The mycrypt extension is not provided with the PHP source since 7.2. The way above is not working anymore.

Updated:

RUN apt install libmcrypt-dev -y \
    && pecl install mcrypt-1.0.1 \
    && docker-php-ext-enable mcrypt

@mlocati
Copy link

mlocati commented Apr 12, 2018

@jungleran Thanks for the tips: I just added support for mcrypt under PHP 7.2 in my install-php-extensions script, so that you can install it simply with one line:

install-php-extensions mcrypt

@trashbat
Copy link

@mlocati Thanks very much for this script, it just saved my weekend! I needed to install 30+ extensions and it was getting incredibly tedious figuring out the dependencies and "gotchas" for each one. Your script worked perfectly 👍

@kelein
Copy link

kelein commented Jun 26, 2018

Excuse me. I install ldap extension based php:5.6-fpm-alpine via docker-php-ext-install ldap, but error occurs:

configure: error: Cannot find ldap.h

ERROR: Service 'php' failed to build: The command '/bin/sh -c apk --update add php5-pdo
 php5-mysqli php5-pdo_mysql php5-ldap && docker-php-ext-configure ldap 
 --with-libdir=lib/x86_64-linux-gnu/ && docker-php-ext-install mysqli ldap && 
 rm -rf /var/cache/apk/*' returned a non-zero code: 1

@rufinus
Copy link

rufinus commented Jun 26, 2018

for ldap i use this (with 7.2)

RUN  apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev openldap-dev && \
    docker-php-ext-install ldap  && \
    docker-php-ext-enable ldap && \
    apk del .build-deps

@mlocati
Copy link

mlocati commented Jan 15, 2020

for ldap i use this (with 7.2)

RUN  apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev openldap-dev && \
    docker-php-ext-install ldap  && \
    docker-php-ext-enable ldap && \
    apk del .build-deps

@rufinus are you sure that the above script is correct?
I recently added Alpine support to my install-php-extensions script (so that you can install for example the ldap PHP extension by simply running install-php-extensions ldap), and that script doesn't install the icu-dev package... Is it required? Furthermore, by calling apk del .build-deps, APK will also uninstall the libldap package which is required by the ldap extension to work (without that package, PHP says PHP Warning: PHP Startup: Unable to load dynamic library 'ldap.so').

@rufinus
Copy link

rufinus commented Jan 15, 2020

@mlocati - you are right this will not work:

it should be:

RUN set -xe \
 && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
 && apk add --no-cache icu-dev openldap-dev \
 && docker-php-ext-install ldap  \
 && docker-php-ext-enable ldap \
 && apk del .build-deps \
 && rm -rf /tmp/* /var/cache/apk/*

@mlocati
Copy link

mlocati commented Jan 15, 2020

Why is icu-dev required? Everything seems to be ok even without installing it...

@rufinus
Copy link

rufinus commented Jan 15, 2020

i copy/pasted it from a current project where i also needed php_intl - maybe its a left over.

@ustccq
Copy link

ustccq commented Jul 31, 2020

@mlocati - you are right this will not work:

it should be:

RUN set -xe \
 && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
 && apk add --no-cache icu-dev openldap-dev \
 && docker-php-ext-install ldap  \
 && docker-php-ext-enable ldap \
 && apk del .build-deps \
 && rm -rf /tmp/* /var/cache/apk/*

Works for me, while from daocloud.io/php:7.2-fpm-alpine, there's no apt-get !

@mlocati
Copy link

mlocati commented Jul 31, 2020

@ustccq as stated above, you can use my install-php-extensions script to easily install the ldap PHP extension (as well as many other extensions), both on Alpine and Debian based Docker images.

@gektor0856
Copy link

@ustccq as stated above, you can use my install-php-extensions script to easily install the ldap PHP extension (as well as many other extensions), both on Alpine and Debian based Docker images.

great! thanks! it works on aarch64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests