hello,
my container is from php:7.0-fpm
i started to run phpmyadmin, but got
The mysqli extension is missing
i then checked the directoy
ls /usr/local/lib/php/extensions/no-debug-non-zts-20151012
opcache.a opcache.so pdo.so pdo_mysql.so
then i seach by apt-cache got nothing
apt-cache search php7-*
how to install mysqli extension for php7?
@zjsxwc https://github.com/docker-library/docs/tree/master/php#php-core-extensions
You can easily add this to your Dockerfile
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
or docker run the image, and then install it from inside the container:
docker exec -ti <your-php-container> sh
>> docker-php-ext-install mysqli
>> docker-php-ext-enable mysqli
>> apachectl restart
You can easily add this to your Dockerfile
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqlior docker run the image, and then install it from inside the container:
docker exec -ti <your-php-container> sh >> docker-php-ext-install mysqli >> docker-php-ext-enable mysqli >> apachectl restart
thank u so much
You can easily add this to your Dockerfile
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqlior docker run the image, and then install it from inside the container:
docker exec -ti <your-php-container> sh >> docker-php-ext-install mysqli >> docker-php-ext-enable mysqli >> apachectl restart
Thankyou so much, that was a problem for some days.
I ran into this exact problem today and was able to update the Dockerfile by adding this line:
RUN docker-php-ext-install mysqli
Unlike some of the comments above, I did not need to run the docker-php-ext-enable command.
Hi, I'm having the same issue.
This is my Dockerfile
FROM php:7.0-apache
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y mysql-client
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-enable mysqli
This is what I'm receiving:
Fatal error: Uncaught Error: Class 'mysqli' not found in /var/www/html/....
What is the workdir for? Try to move that after the last RUN or remove it.
Also what do you need mysql-client for in a php container?
My PHP application connects to a MySQL Server. The program uses mysqli and some answers include the installation of those packages.
mysql-client is only needed for command line access to the database. Even if you want to do it you most probably want to do it from outside or another container.
I've removed the WORKDIR and now it's working...

These instructions were perfect but I'm having difficulty adding the necessary commands to my docker-compose file.
Each time the container is stopped and restarted, I have to manually execute the install. Is there a way to add it to a docker-compose.yml file? I tried adding:
command: "/bin/sh -c 'docker-php-ext-install mysqli && apachectl restart'"
But after doing so the container stops prematurely.
You need to create your own image with a Dockerfile based on (FROM php:xy) the version you want in which you install mysqli via RUN docker-php-ext-install ... and reference that from your compose file. Restarting the apache of course stops the container, because apache is its main process - it is unneeded anyways in the Dockerfile
@JoelLinn thanks for the comment. It's just odd because when I run apachectl restart from within the container, it doesn't stop the container and everything works as normal. Hmm...
That being said, sounds like creating my own Dockerfile is the way to go.
@sohmc, apachectl restart exits and so there is nothing for the container to track, so it also exits. (FYI, there is no init system in the container). You probably wanted something like this (just ending with the default entrypoint + command):
command: "/bin/sh -c 'docker-php-ext-install mysqli && exec docker-php-entrypoint apache2-foreground'"
# can leave off the default entrypoint of "docker-php-entrypoint"
# since what it does isn't necessary here
command: "/bin/sh -c 'docker-php-ext-install mysqli && exec apache2-foreground'"
Building a Dockerfile would be better since you'll most likely need other extensions and they may have apt dependencies that also need to be installed.
Bom dia, boa tarde ou boa noite,
Esta 茅 uma mensagem autom谩tica para lhe informar que a Loooping est谩 de f茅rias e retorna as atividades no dia 07/01/2020.
Portanto qualquer solicita莽茫o feita atrav茅s deste e-mail, telefone, ou outros softwares utilizados para suporte n茫o ser茫o atendidas antes disso, na retomada responderemos tudo em ordem cronol贸gica.
Desejamos boas festas, muita sa煤de e sucesso para voc锚 e toda a sua fam铆lia.
Nos vemos em 2020 e muito obrigado pela prefer锚ncia por mais um ano juntos.
I also had the same problem, my Dockerfile have this content:
FROM php:7.4-apache
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli && apachectl restart
EXPOSE 80
My question is, how to start the Dockerfile first and then the docker-compose.yml file?
From terminal I give this command: docker-compose up -d
Next I have to go into the container: docker exec -ti 81385f7e6c39 sh
And give the following command: docker-php-ext-install mysqli && docker-php-ext-enable mysqli && apachectl restart
Dockerfile is not being read, how can I fix it?
My goal is to do everything automatically, without having to enter the container, is it possible?
You need to edit your docker-compose.yml to use build: . instead of image: php:xxx.
In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.
Most helpful comment
You can easily add this to your Dockerfile
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqlior docker run the image, and then install it from inside the container: