mysqli is missing in a PHP Docker container
mysqli not found in dockerized PHPShort answer
The official php image ships a small set of extensions, so mysqli is often absent. Run php -m in the container to confirm, add RUN docker-php-ext-install mysqli (and pdo_mysql if you use PDO) to the Dockerfile, then rebuild the image so the running container actually uses it.
Fix it fast
1Find out which cause you have
List the extensions loaded in the running container, not on your host. Look for mysqli and pdo_mysql.
docker exec my-php php -m | grep -iE 'mysqli|pdo_mysql'2Match what you see, then jump to its fix
- 1
php -m prints nothing for mysqliThe extension was never installed in the imageFix - 2
The Dockerfile has the install line, but php -m in the running container is unchangedThe Dockerfile was fixed but the container still runs the old imageFix - 3
mysqli is listed, but PDO fails to find the MySQL driverYour code uses PDO, which needs its own driverFix
- 1
What does the error look like?
mysqli not found in dockerized PHPphp -m does not list mysqliPDO MySQL driver missing although mysqli works
Cause 1 of 3
The extension was never installed in the image
1Check
The image page says many extensions are already compiled in, and tells you to check with php -m before adding more. If mysqli is not listed, it is not there.
docker run --rm php:8.3-cli php -m2Fix
Install it with the helper script that the official image provides.
# Dockerfile
FROM php:8.3-apache
RUN docker-php-ext-install mysqli3Verify
Build the image and list the modules again.
docker build -t my-php .
docker run --rm my-php php -m | grep mysqliConfirmed by hub.docker.com
Cause 2 of 3
The Dockerfile was fixed but the container still runs the old image
1Check
docker compose build builds and tags a service image, and you have to run it again when the Dockerfile changes. A running container keeps the image it was created from.
docker compose images
docker compose exec php php -m | grep mysqli2Fix
Rebuild without cache if a stale layer is suspected, then recreate the container.
docker compose build --no-cache php
docker compose up -d3Verify
The module list inside the new container now shows mysqli.
docker compose exec php php -m | grep mysqliConfirmed by docs.docker.com
Cause 3 of 3
Your code uses PDO, which needs its own driver
1Check
The PHP manual lists PDO_MYSQL and mysqli as separate extensions, each installed on its own. Having one does not give you the other.
docker exec my-php php -m | grep -iE '^pdo|mysqli'2Fix
Install the PDO driver too, using the same helper script.
RUN docker-php-ext-install mysqli pdo_mysql3Verify
Rebuild, then confirm both modules.
docker run --rm my-php php -m | grep -iE 'mysqli|pdo_mysql'Confirmed by php.net
How do I stop it coming back?
- Run php -m against your final image in CI so a missing extension fails the build, not production.
- Keep every extension in the Dockerfile; do not install them by hand in a running container.
- Pin the PHP tag (for example php:8.3-apache) so the extension set does not change under you.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Back end
Laravel cannot find the database host: getaddrinfo failed
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed
The message means PHP could not turn DB_HOST into an IP address.
3 causes, each with a fixBack end
CodeIgniter 4: try/catch does not catch a failed insert in the model
DatabaseException
CodeIgniter throws a DatabaseException on a failed query only when DBDebug is true, and inside a transaction it does not throw unless you ask.
3 causes, each with a fixBack end
CodeIgniter 4 where() builds a different condition than you meant
A SQL syntax error that appears only when a value contains a quote character
The query builder joins every where() with AND and every orWhere() with OR, with no brackets.
3 causes, each with a fixBack end
Call to undefined function mysql_pconnect() after a PHP upgrade
Call to undefined function mysql_connect()
The old mysql_* functions belonged to the ext/mysql extension, which PHP removed in version 7.0.
2 causes, each with a fixBack end
CodeIgniter cannot connect to the MySQL database server
Unable to connect to your database server using the provided settings.
CodeIgniter only reports that its connection failed.
4 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fix