Home >Database >Mysql Tutorial >How to Install the PDO MySQL Driver in Your PHP Docker Image?
Install PDO Driver in PHP Docker Image
Background:
You're encountering an error while trying to access a database in your PHP application within a Docker container. The error indicates that the PDO MySQL driver is missing.
Solution:
The official PHP repository provides a script for installing PHP extensions in Docker containers: docker-php-ext-install. To resolve this issue:
FROM php:5.6-apache # Install PDO extension RUN docker-php-ext-install pdo pdo_mysql
Build and install the customized Docker image with the PDO extension:
docker build -t custom-php-image . docker run -it --rm --name my-app custom-php-image
Now, your Docker container will have the PDO MySQL driver installed and you should be able to access your database without encountering the PDO driver missing error.
The above is the detailed content of How to Install the PDO MySQL Driver in Your PHP Docker Image?. For more information, please follow other related articles on the PHP Chinese website!