How to Install PDO Driver in PHP Docker Image
This article addresses the issue of installing the PDO driver for PHP within a Docker container. The provided PHP Docker image with the tag "php:5.6-apache" does not include the PDO driver by default.
Problem
The error message "Fatal error: Uncaught exception 'PDOException' with message could not find driver" indicates that the PDO driver is missing. Attempts to install the "php-mysql" component via "apt-get install php5-mysql" and add a "mysql.ini" file in "/usr/local/etc/php/conf.d/" were unsuccessful.
Solution
The docker-php-ext-install script, provided by the official PHP Docker repository, can be used to install the PDO driver.
FROM php:5.6-apache # PHP extensions RUN docker-php-ext-install pdo pdo_mysql
This command will install both the PDO and the PDO_MYSQL extensions within the Docker container.
The above is the detailed content of How to Install PDO Driver in a PHP Docker Image?. For more information, please follow other related articles on the PHP Chinese website!