Install / Configure SQL Server PDO driver for PHP docker image

假装没事ソ 提交于 2020-04-11 03:52:27

问题


I have a simple docker file, as follows:

FROM php:7.2-apache
COPY src/ /var/www/html/

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

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.

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.

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

Thanks all


回答1:


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.)

in the Docker file:

RUN apt-get -y install unixodbc-dev
RUN pecl install sqlsrv pdo_sqlsrv

And then you have to add some changes to php.ini to enable sqlserver.

get a local copy of php.ini and add these lines:

extension=pdo_sqlsrv.so
extension=sqlsrv.so

Then copy your local php.ini into the docker image (my file is in a local "config" folder).

in the Docker file:

COPY config/php.ini /usr/local/etc/php/


来源:https://stackoverflow.com/questions/51933001/install-configure-sql-server-pdo-driver-for-php-docker-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!