Home > Database > Mysql Tutorial > How to Install PDO Driver in a PHP Docker Image?

How to Install PDO Driver in a PHP Docker Image?

Barbara Streisand
Release: 2024-11-08 20:15:02
Original
223 people have browsed it

How to Install PDO Driver in a PHP Docker Image?

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template