为PHP docker映像安装/配置SQL Server PDO驱动程序 [英] Install / Configure SQL Server PDO driver for PHP docker image
问题描述
我有一个简单的docker文件,如下所示:
I have a simple docker file, as follows:
FROM php:7.2-apache
COPY src/ /var/www/html/
通常要安装用于Mongo或MySQL连接的驱动程序,我可以通过将以下内容添加到dockerfile中来实现:
Normally to install drivers for Mongo or MySQL connectivity I would do so by adding something like the below to the dockerfile:
docker-php-ext-install mongo
在这种情况下,我想将php应用程序连接到SQL Server数据库,并且我了解为php 7.x做到这一点的最佳方法是使用PDO驱动程序,但是我不熟悉如何配置它在dockerfile中.
On this occasion I want to connect my php application to a SQL Server database, and I understand the best way to do this for php 7.x is by using the PDO driver, however I am unfamiliar with how to do configure this in the dockerfile.
我尝试执行pecl安装,例如添加:
I've tried doing a pecl install, like adding:
RUN pecl install sqlsrv pdo_sqlsrv
但是,这失败了,并且出现了一些错误,这些错误似乎并没有向我指出正确的方向.
However this fails with a combination of errors that do not seem to point me in the right direction.
我只是在寻找一种简单的方法来通过dockerfile或使用docker run来完成此操作.
I'm just looking for a simple way to get this done in a dockerfile or by using docker run.
有关其他信息,这是我遇到的错误:
For added info, here's the error I'm getting:
/tmp/pear/temp/sqlsrv/shared/xplat.h:30:17: fatal error: sql.h: No such file or directory
#include <sql.h>
^
compilation terminated.
Makefile:194: recipe for target 'conn.lo' failed
make: *** [conn.lo] Error 1
ERROR: `make' failed
The command '/bin/sh -c pecl install sqlsrv pdo_sqlsrv && docker-php-ext-enable pdo_sqlsrv' returned a non-zero code: 1
谢谢
推荐答案
您得到了答案吗?我按照以下步骤进行操作. (unixodbc-dev软件包应该使您摆脱了pecl的安装.)
Did you get an answer to this? I got it working with the following steps. (The unixodbc-dev package should get you past the pecl install.)
在Docker文件中:
in the Docker file:
RUN apt-get -y install unixodbc-dev
RUN pecl install sqlsrv pdo_sqlsrv
然后必须对php.ini添加一些更改以启用sqlserver.
And then you have to add some changes to php.ini to enable sqlserver.
获取php.ini的本地副本并添加以下行:
get a local copy of php.ini and add these lines:
extension=pdo_sqlsrv.so
extension=sqlsrv.so
然后将您的本地php.ini复制到docker映像中(我的文件位于本地的"config"文件夹中).
Then copy your local php.ini into the docker image (my file is in a local "config" folder).
在Docker文件中:
in the Docker file:
COPY config/php.ini /usr/local/etc/php/
这篇关于为PHP docker映像安装/配置SQL Server PDO驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!