如何在 php docker 镜像中安装 pdo 驱动程序? [英] How to install pdo driver in php docker image?

查看:77
本文介绍了如何在 php docker 镜像中安装 pdo 驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有标签的 php docker 容器 作为基础:

I am using as a base the php docker container with the tag:

php:5.6-apache

我将它与一个基本的 mysql:5.6 图像链接起来,我可以在主机 mysql 上访问它.我创建了一个数据库,并用基本值填充了一个表.

I linked it with a basic mysql:5.6 image which I can reach at the host mysql. I created a DB, and filled a table with basic values.

但尝试访问我的应用时,我得到:

Yet trying to access my app, I get:

Fatal error: Uncaught exception 'PDOException' with message
could not find driver' in /var/www/html/index.php:30 
Stack trace: #0 [internal function]: 
PDO->__construct('mysql:host=mysq...', 'root', 'root', Array) 
#1 [internal function]: Phalcon\Db\Adapter\Pdo->connect(Array)
#2 /var/www/html/index.php(30): Phalcon\Db\Adapter\Pdo-__construct(Array)
#3 [internal function]: {closure}()
#4 [internal function]: Phalcon\Di\Service->resolve(NULL, Object(Phalcon\Di\FactoryDefault))
#5 [internal function]: Phalcon\Di->get('db', NULL)
#6 [internal function]: Phalcon\Di->getShared('db')
#7 [internal function]: Phalcon\Mvc\Model\Manager->_getConnection(Object(Reviews), NULL)
#8 [internal function]: Phalcon\Mvc\Model\Manager->getReadConnection(Object(Reviews))
#9 [internal function]: Phalcon\Mvc\Model->getReadConnection()
#10 [internal function]: Phalcon\Mvc\Model\MetaData\Strategy\Introspection->getMetaData(Object(Reviews), Object(Phalcon\Di\FactoryDefault))
#11 [internal function]: Phalcon\Mvc\Model\MetaData->_initialize(Object(Rev in /var/www/html/index.php on line 30

因此,我认为 php 容器缺少我通过以下方式安装的 php-mysql 组件:

Hence, I thought that the php container was lacking the php-mysql component I installed via:

apt-get install php5-mysql

我还在以下位置添加了一个 mysql.ini:

I also added a mysql.ini at:

cat /usr/local/etc/php/conf.d/mysql.ini
; configuration for php MySQL module
; priority=20
extension=pdo_mysql.so

如果我 echo phpinfo();die 它告诉我:

Additional .ini files parsed:
    /usr/local/etc/php/conf.d/mysql.ini,
    /usr/local/etc/php/conf.d/phalcon.ini

然而,错误仍然存​​在.

Yet still, the error persists.

此外,在运行时:

php -i|grep PDO

我明白了:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo_mysql.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PDO
PDO support => enabled
PDO drivers => sqlite
PDO Driver for SQLite 3.x => enabled

所以似乎 mysql 扩展甚至没有被激活.

so it seems the mysql extension isn't even activated.

我做错了什么?

推荐答案

PHP 的官方仓库有一个脚本叫做 docker-php-ext-install https://github.com/docker-library/php/tree/master/5.6

您忘记安装运行 PDO 所需的扩展.

You forgot to install the extension needed to run the PDO.

尝试像这样创建一个 docker 镜像:

Try do create a docker image like this:

FROM php:5.6-apache

# PHP extensions

RUN docker-php-ext-install pdo pdo_mysql pdo_pgsql

这篇关于如何在 php docker 镜像中安装 pdo 驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆