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

How do you get php-mysql extensions installed for php:7-fpm-alpine #279

Closed
chrissound opened this issue Jul 31, 2016 · 15 comments
Closed

How do you get php-mysql extensions installed for php:7-fpm-alpine #279

chrissound opened this issue Jul 31, 2016 · 15 comments

Comments

@chrissound
Copy link

It seems the 'php7-mysqli' extension is not available?

FROM php:7-fpm-alpine 

RUN apk --no-cache update \
    && apk --no-cache upgrade \
    && apk add --no-cache php7-mysqli
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM php:7-fpm-alpine
 ---> 50b972b9e729
Step 2 : RUN apk --no-cache update     && apk --no-cache upgrade     && apk add --no-cache php7-mysqli
 ---> Running in a04fecd6c73a
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
v3.4.2-2-gd037d87 [http://dl-cdn.alpinelinux.org/alpine/v3.4/main]
v3.4.1-50-gd7c21d4 [http://dl-cdn.alpinelinux.org/alpine/v3.4/community]
OK: 5967 distinct packages available
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
OK: 16 MiB in 25 packages
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  php7-mysqli (missing):
    required by: world[php7-mysqli]
The command '/bin/sh -c apk --no-cache update     && apk --no-cache upgrade     && apk add --no-cache php7-mysqli' returned a non-zero code: 1
@hairmare
Copy link

The alpine images do not install php from apk sources. In this case, adding mysqli is very easy using docker-php-ext-install.

FROM php:7-fpm-alpine
RUN docker-php-ext-install mysqli

@chrissound
Copy link
Author

I see... Curious as to why though? Surely this means additional complexity as you are required to handle dependencies (of the extension).

@hairmare
Copy link

hairmare commented Aug 1, 2016

It's about being closer to upstream PHP and to have version parity with debian images (#218 (comment)).

In the alpine case docker-php-ext-install does a smart job using apk to figure out what dependencies are needed, debian users have to install their deps manually.

@adambuczek
Copy link

adambuczek commented Jul 18, 2017

EDIT: it turned out to be PHP misconfiguration

I have the same problem with 7.1. It builds ok but the extensions are not installed.

FROM php:7.1-fpm-alpine
RUN docker-php-ext-install mysqli pdo pdo_mysql

I tried to include /usr/local/lib/php/extensions/no-debug-non-zts-20160303/ which was created during build but it makes no difference.

@hairmare
Copy link

@adambuczek I can't reproduce the issue using the Dockerfile you posted.
Maybe your local php:7.1-fpm-alpine image is outdated? Try running docker pull php:7.1-fpm-alpine before building to see if it fixes the issue.

@manuelmanhart
Copy link

@hairmare I tried that, and it did not work for me either.

My Dockerfile looks like this

FROM php:7.1-fpm-alpine
MAINTAINER Manuel Manhart
VOLUME /code
#WORKDIR /code
RUN   apk update \                                                                                                                                                                                                                        
  &&   apk add ca-certificates wget \                                                                                                                                                                                                      
  &&   update-ca-certificates
RUN docker-php-ext-install mysqli && \
    docker-php-ext-install pdo_mysql

During the docker-compose build it looks good:

Libraries have been installed in:
   /usr/src/php/ext/pdo_mysql/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.

But when I start the container there is no /usr/src/php directory, also the extensions are located in /usr/local/include/php/ext.

I tried executing the docker-php-ext-install command from inside the container, this creates the /usr/src/php/... dir but the extension is not loaded in php.

Can you give some hints?

@hairmare
Copy link

hairmare commented Aug 5, 2017

@manuelmanhart The /usr/local/include/php/ext looks alright, The actual ini file that ext install uses should be in /usr/local/etc/php/conf.d.

/usr/src/php ist used by the install script temporarily and then removed so the complete unpackaged php source doesn't end up in an image layer.

Are you sure your image is up to date? You can ensure that it is up-to-date with docker-compose by running docker-compose build --pull

@sociaqui
Copy link

had a similar problem, wouldn't cooperate until I added && docker-php-ext-enable pdo_mysql after RUN docker-php-ext-install mysqli pdo pdo_mysql

@hichamuntitled
Copy link

I am running into the same problem. Actually, when I install mysqli and pdo using docker-php-ext-install mysqli pdo pdo_mysql the related files are created in /usr/local/lib/php/extensions/no-debug-non-zts-20170718/ directory, bu I can't find them when I run a phpinfo(); even if i set this location in the php.ini file. This problem seems to be only on alpine.

@craigvanaman
Copy link

Using docker-php-ext-install didn't install the mysql extension in a way that my nginx unit could detect. While running php -i on the cli showed everything as groovy, the php used by my nginx unit install seemed totally out of whack. Eventually apk add php7-mysqli fixed it.

FROM alpine:3.9
ARG BUILD_DIR="./.docker"

# install PHP & nginx unit
RUN apk add --no-cache curl wget unzip
RUN apk update && apk upgrade
RUN apk add unit unit-php7 
RUN apk add php7 php7-fpm php7-mysqli php7-opcache php7-gd php7-mysqli php7-zlib php7-curl php7-phar php7-json php7-mbstring 

# install composer
COPY ${BUILD_DIR}/install-composer.sh /tmp/composer-install.sh
RUN chmod 777 /tmp/composer-install.sh && /tmp/composer-install.sh

# Activate the nginx unit config
COPY ${BUILD_DIR}/unit-config.json /tmp/app.json
RUN unitd && curl -s -X PUT -d @/tmp/app.json --unix-socket /var/run/control.unit.sock http://localhost/config

WORKDIR /var/www/html/
CMD ["unitd", "--no-daemon"]

@yosifkit
Copy link
Member

@craigvanaman assuming that you had a previous Dockerfile with FROM php:7-alpine of some sort, then most likely you were getting two versions of php in your image and nginx was using the one from Alpine's packages (which is why we made a fix to prevent that in the Debian images with #542). Your Dockerfile looks like a great workaround to just skip our php images altogether.

@ahmed-mahmoud-allmyhomes

`FROM php:7.2-fpm

RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

`

@profseb
Copy link

profseb commented Mar 18, 2020

I wanna know how to put

RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

no using a Dockerfile

@tianon
Copy link
Member

tianon commented Mar 18, 2020

@profseb you mean something like this?

$ docker run ... php:7.2 sh -c 'docker-php-ext-install mysqli && exec php ...'

It seems a little silly to compile it every time the container starts/restarts, especially given how easy it is to just docker build a 2-line Dockerfile, but should be reasonably harmless.

@waellkh

This comment has been minimized.

@docker-library docker-library locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests