dongnan
总版主
总版主
  • 粉丝52
  • 发帖数2160
  • 铜币13127枚
  • 威望5808点
  • 银元150个
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 原创写手
阅读:3107回复:4

docker 环境 php 容器安装扩展模块

楼主#
更多 发布于:2017-03-10 10:08
目标
为 php 容器安装扩展模块;

问题描述

图片:docker-php-mysql-driver.png


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 CenOS 7.3
phpwind 9.0

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

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

解决方法
1. 首先进入容器
docker exec -ti ywwd-php /bin/bash
2. 使用官方工具完成扩展模块安装
docker-php-ext-install pdo_mysql
3. 验证
php -m | grep -i 'mysql'
mysql
pdo_mysql

扩展:  我的 docker 环境 所使用 php 扩展模块
# core
docker-php-ext-install bcmath dba exif mysqli pdo_mysql sysvsem sysvshm

# pecl
apt-get update \

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

apt-get install libmagickwand-dev \
    && pecl install imagick \
    && docker-php-ext-enable imagick

apt-get install libmemcached-dev \
    && pecl install memcached \
    && docker-php-ext-enable memcached
    
pecl install redis && docker-php-ext-enable redis

apt-get install bzip2 -y \
    && docker-php-ext-install bz2 zip

参考: How to install more PHP extensions
推荐: 使用 docker-compose 部署 phpwind
#
dongnan
总版主
总版主
  • 粉丝52
  • 发帖数2160
  • 铜币13127枚
  • 威望5808点
  • 银元150个
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 原创写手
沙发#
发布于:2017-04-10 21:27
nginx Dockerfile 配置文件(定制)
cat Dockerfile
# zm-web

FROM      nginx:latest
MAINTAINER dongnan <http://zongming.net>

# apt
COPY conf/sources.list /etc/apt/sources.list
# RUN apt-get update

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

# nginx
COPY conf/nginx.conf /etc/nginx/nginx.conf
COPY conf/default.conf /etc/nginx/conf.d/default.conf
COPY conf/ywwd.conf /etc/nginx/conf.d/ywwd.conf
COPY conf/ssl /etc/nginx/ssl

# expose port
#EXPOSE 8080

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

#
dongnan
总版主
总版主
  • 粉丝52
  • 发帖数2160
  • 铜币13127枚
  • 威望5808点
  • 银元150个
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 原创写手
板凳#
发布于:2017-05-25 10:43
php:5.6-fpm 我的 Dockerfile 配置文件(定制)
cat Dockerfile
# php-5.6

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

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

# apt
COPY conf/sources.list /etc/apt/sources.list
RUN apt-get update \
    && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
        libmagickwand-dev \
        libmemcached-dev \
        bzip2 \
    && apt-get clean \
    && rm -r /var/lib/apt/lists/*

# php ext
RUN docker-php-ext-install bcmath \
    dba \
    exif \
    mysqli \
    pdo_mysql \
    sysvsem \
    sysvshm \
    bz2 \
    zip \
    mysql

RUN 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 \
    memcached-2.2.0 \
    redis \
    && docker-php-ext-enable imagick \
    && docker-php-ext-enable memcached \
    && docker-php-ext-enable redis


#ADD conf/cert /etc/nginx/cert/
ADD conf/php.ini /usr/local/etc/php/php.ini
ADD conf/www.conf /usr/local/etc/php-fpm.d/www.conf

#EXPOSE 8080

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


#END
dongnan
总版主
总版主
  • 粉丝52
  • 发帖数2160
  • 铜币13127枚
  • 威望5808点
  • 银元150个
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 原创写手
地板#
发布于:2017-11-30 10:30
php-fpm-56 + nginx 定制 Dockerfile
目录
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
cat 5.6/Dockerfile
# php-fpm:5.6
#
# VERSION               0.0.1

FROM     php:5.6-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 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"]

#
dongnan
总版主
总版主
  • 粉丝52
  • 发帖数2160
  • 铜币13127枚
  • 威望5808点
  • 银元150个
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 原创写手
4楼#
发布于:2017-11-30 10:32
php-fpm-71 + nginx 定制 Dockerfile
目录
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
cat 7.1/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"]
#
游客

返回顶部