跳转至

如何使用docker-php-ext-install安装扩展模块?


2017-03-10 by dongnan

目标

php 容器 安装 pdo_mysql扩展模块。

问题描述

Uncaught error with message [db.WindConnection.init] could not find driver The server encountered an internal error and failed to process your request. Please try again later. If this error is temporary, reloading the page might resolve the problem. If you are able to contact the administrator report this error message.(http://www.windframework.com/)

环境

php-5.6 on Docker 1.13 on CentOS 7.3
phpwind 9.0

错误原因

检查容器

docker exec -ti ywwd-php php -m | grep -i 'mysql'
mysqlnd

php-5.6 为 PHP官方维护的 docker 镜像,php团队为保持轻量级的镜像,默认没有安装 pdo_mysql模块,所以需要为 php 安装 pdo_mysql扩展模块。

解决方法

进入容器

docker exec -ti ywwd-php /bin/bash

使用官方提供的工具安装扩展模块

docker-php-ext-install pdo_mysql

验证模块

php -m | grep -i 'mysql'
mysql
pdo_mysql

扩展

php5 定制 Dockerfile

软件: php-fpm:5.6 + nginx

目录结构

tree 5.6/
5.6/
├── conf
│   ├── crontab
│   ├── default.conf
│   ├── nginx.conf
│   ├── php-docker.conf
│   ├── php.ini
│   ├── php-www.conf
│   ├── sources.list
│   ├── sources.list.163
│   └── supervisord.conf
└── Dockerfile

1 directory, 10 files

Dockerfile

# php-fpm:5.6
#
# VERSION               0.0.1

FROM     php:5.6-fpm
MAINTAINER dongnan

# apt
ADD conf/sources.list /etc/apt/sources.list
RUN apt-get update && apt-get install -y supervisor cron nginx

# php depend OS package
RUN apt-get install -y libmagickwand-dev bzip2 libmemcached-dev

# pecl
RUN docker-php-ext-install bcmath dba exif pdo_mysql bz2 zip mysql
#
RUN apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd
#
RUN pecl install imagick && docker-php-ext-enable imagick
#
RUN pecl install memcached-2.2.0 && docker-php-ext-enable memcached
#php7: pecl install memcached \
#
RUN pecl install redis && docker-php-ext-enable redis

# configure file
# php
ADD conf/php.ini /usr/local/etc/php/php.ini
ADD conf/php-www.conf /usr/local/etc/php-fpm.d/www.conf
ADD conf/php-docker.conf /usr/local/etc/php-fpm.d/docker.conf

# nginx
ADD conf/nginx.conf /etc/nginx/nginx.conf
ADD conf/default.conf /etc/nginx/conf.d/default.conf

# cron
COPY conf/crontab /var/spool/cron/crontabs/root
RUN chmod 600 /var/spool/cron/crontabs/root

# supervisor
RUN mkdir -p /var/log/supervisor &&  mkdir -p /var/log/php
ADD conf/supervisord.conf /etc/supervisor/supervisord.conf

# apt-cache clean
RUN apt-get clean && rm -r /var/lib/apt/lists/*

# env
ENV TZ=Asia/Shanghai
ENV LANG=en_US.UTF-8

#
EXPOSE 80

#
CMD ["/usr/bin/supervisord","-c","/etc/supervisor/supervisord.conf"]

php7 定制 Dockerfile

软件: php-fpm:7.1 + nginx

目录结构

tree 7.1/
7.1/
├── conf
│   ├── crontab
│   ├── default.conf
│   ├── nginx.conf
│   ├── php-docker.conf
│   ├── php.ini
│   ├── php-www.conf
│   ├── sources.list
│   ├── sources.list.163
│   └── supervisord.conf
└── Dockerfile

1 directory, 10 files

Dockerfile

# php-fpm:7.1
#
# VERSION               0.0.1

FROM     php:7.1-fpm
MAINTAINER dongnan <http://zongming.net>

# apt
ADD conf/sources.list /etc/apt/sources.list
RUN apt-get update && apt-get install -y supervisor cron nginx

# php depend OS package
RUN apt-get install -y libmagickwand-dev bzip2 libmemcached-dev

# pecl
RUN docker-php-ext-install bcmath dba exif pdo_mysql bz2 zip
#
RUN apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd
#
RUN pecl install imagick && docker-php-ext-enable imagick
#
RUN pecl install memcached && docker-php-ext-enable memcached
#
RUN pecl install redis && docker-php-ext-enable redis

# configure file
# php
ADD conf/php.ini /usr/local/etc/php/php.ini
ADD conf/php-www.conf /usr/local/etc/php-fpm.d/www.conf
ADD conf/php-docker.conf /usr/local/etc/php-fpm.d/docker.conf

# nginx
ADD conf/nginx.conf /etc/nginx/nginx.conf
ADD conf/default.conf /etc/nginx/conf.d/default.conf

# cron
COPY conf/crontab /var/spool/cron/crontabs/root
RUN chmod 600 /var/spool/cron/crontabs/root

# supervisor
RUN mkdir -p /var/log/supervisor &&  mkdir -p /var/log/php
ADD conf/supervisord.conf /etc/supervisor/supervisord.conf

# apt-cache clean
RUN apt-get clean && rm -r /var/lib/apt/lists/*

# env
ENV TZ=Asia/Shanghai
ENV LANG=en_US.UTF-8

#
EXPOSE 80

#
CMD ["/usr/bin/supervisord","-c","/etc/supervisor/supervisord.conf"]

参考

回到页面顶部