Mysql – How to configure PHP 7 – Apache with MySQL PDO driver in Debian Docker image

apachedockerMySQLpdophp-7

I'm using official docker images for PHP 7 (7.0.3-Apache) and MySql (5.7.10).
Using docker-compose, created containers from images and linked both.

Copied php.ini from https://github.com/php/php-src/blob/php-7.0.3/php.ini-production, replaced dll extensions with so and placed that file in /usr/local/etc/php and enabled _pdo_mysql_ extension in it.
extension=php_pdo_mysql.so

phpinfo shows php.ini loaded but not pdo_mysql extension because it's not installed.

I googled and tried different extension names with apt-get install:
php-mysql, php7-mysql, php7.0-mysql, php7.0.3-mysql.

None of them works. Error says: E: Unable to locate package.

With php5-mysql, it's get installed but after restarting apache with command: docker kill --signal="USR1" <container-name>, extension doesn't show loaded in php.ini.

(Don't think it's much related to docker but I'm new to docker and trying with that now, so mentioning it here.)

Can anyone help to configure pdo_mysql extension with php7-Apache?

Best Answer

You need the Dotdeb repository in /etc/apt/sources.list on your docker image:

FROM php:7-apache

# Install pdo_mysql
RUN apt-get update \
  && echo 'deb http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list \
  && echo 'deb-src http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list \
  && apt-get install -y wget \
  && wget https://www.dotdeb.org/dotdeb.gpg \
  && apt-key add dotdeb.gpg \
  && apt-get update \
  && apt-get install -y php7.0-mysql \
  && docker-php-ext-install pdo_mysql