Install and configuration

Jenny Tam edited this page Sep 17, 2018 · 29 revisions

Contents

End to End Installation instructions

Linux and macOS Installation Tutorial for the Microsoft Drivers for PHP for SQL Server

Common installation and configuration issues

Please browse the Frequently Asked Questions

Docker files

This section is created and maintained by contributors, and is not officially tested.

Dockerfile for adding pdo_sqlsrv and sqlsrv to official php image.

Originally created by Diego Gullo

This uses Microsoft repos for msodbcsql to simplify the installation process.

FROM php:fpm

# Add Microsoft repo for Microsoft ODBC Driver 13 for Linux
RUN apt-get update && apt-get install -y \
    apt-transport-https \
    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update

# Install Dependencies
RUN ACCEPT_EULA=Y apt-get install -y \
    unixodbc \
    unixodbc-dev \
    libgss3 \
    odbcinst \
    msodbcsql \
    locales \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen

# Install pdo_sqlsrv and sqlsrv from PECL. Replace pdo_sqlsrv-4.1.8preview with preferred version.
RUN pecl install pdo_sqlsrv-4.1.8preview sqlsrv-4.1.8preview \
    && docker-php-ext-enable pdo_sqlsrv sqlsrv

Dockerfile for getting pdo_sqlsrv for PHP 7.0 on Debian in 3 ways

Originally created by Viktor Szépe

# Prove that the Debian how-to works, please choose one of the 3 installation methods
# and optionally save the resulting extension: sudo cp /usr/lib/php/20151012/pdo_sqlsrv.so /opt/results/

FROM szepeviktor/jessie-build

ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive

USER debian
WORKDIR /home/debian
VOLUME ["/opt/results"]

# Add PHP 7 repository
# for Debian jessie
# And System upgrade
RUN echo "deb http://packages.dotdeb.org jessie all" \
    | sudo tee /etc/apt/sources.list.d/dotdeb.list \
    && wget -qO- https://www.dotdeb.org/dotdeb.gpg \
    | sudo apt-key add - \
    && sudo apt-get update \
    && sudo apt-get upgrade -qq

# Install UnixODBC
# Compile odbc_config as it is not part of unixodbc package
RUN sudo apt-get install -y whiptail \
    unixodbc libgss3 odbcinst devscripts debhelper dh-exec dh-autoreconf libreadline-dev libltdl-dev \
    && dget -u -x http://http.debian.net/debian/pool/main/u/unixodbc/unixodbc_2.3.1-3.dsc \
    && cd unixodbc-*/ \
De    && dpkg-buildpackage -uc -us -B \
    && sudo cp -v ./exe/odbc_config /usr/local/bin/

# Fake uname for install.sh
RUN printf '#!/bin/bash\nif [ "$*" == "-p" ]; then echo "x86_64"; else /bin/uname "$@"; fi' \
    | sudo tee /usr/local/bin/uname \
    && sudo chmod +x /usr/local/bin/uname

# Microsoft ODBC Driver 13 for Linux
# Note: There's a copy of this tar on my hubiC
RUN wget -nv -O msodbcsql-13.0.0.0.tar.gz \
    "https://meetsstorenew.blob.core.windows.net/contianerhd/Ubuntu%2013.0%20Tar/msodbcsql-13.0.0.0.tar.gz?st=2016-10-18T17%3A29%3A00Z&se=2022-10-19T17%3A29%3A00Z&sp=rl&sv=2015-04-05&sr=b&sig=cDwPfrouVeIQf0vi%2BnKt%2BzX8Z8caIYvRCmicDL5oknY%3D" \
    && tar -xf msodbcsql-13.0.0.0.tar.gz \
    && cd msodbcsql-*/ \
    && ldd lib64/libmsodbcsql-13.0.so.0.0 \
    && sudo ./install.sh install --accept-license \
    && ls -l /opt/microsoft/msodbcsql/ \
    && odbcinst -q -d -n "ODBC Driver 13 for SQL Server"

# (1) Install PDO driver from pecl
RUN sudo apt-get install -y unixodbc-dev php7.0-dev php-pear \
    && sudo pecl channel-update pecl.php.net \
    && sudo pecl install pdo_sqlsrv \
    && printf "; priority=20\nextension=pdo_sqlsrv.so" \
    | sudo tee /etc/php/7.0/mods-available/pdo_sqlsrv.ini \
    && sudo phpenmod pdo_sqlsrv \
    && php --rextinfo pdo_sqlsrv \
    && sudo phpdismod pdo_sqlsrv \
    && sudo pecl uninstall pdo_sqlsrv

# (2) Or Build PDO driver with phpize
RUN sudo apt-get install -y unixodbc-dev php7.0-dev \
    && wget -nv "https://github.com/Microsoft/msphpsql/archive/PHP-7.0-Linux.tar.gz" \
    && tar -xf PHP-7.0-Linux.tar.gz \
    && cd msphpsql-PHP-7.0-Linux/source/ \
    && cp -r shared/ pdo_sqlsrv/ \
    && cd pdo_sqlsrv/ \
    && phpize \
    && ./configure CXXFLAGS=-std=c++11 \
    && make \
    && sudo make "INSTALL=$(pwd)/build/shtool install -c --mode=0644" install \
    && printf "; priority=20\nextension=pdo_sqlsrv.so" \
    | sudo tee /etc/php/7.0/mods-available/pdo_sqlsrv.ini \
    && sudo phpenmod pdo_sqlsrv \
    && php --rextinfo pdo_sqlsrv \
    && sudo phpdismod pdo_sqlsrv \
    && sudo rm -f /usr/lib/php/20151012/pdo_sqlsrv.so

# (3) Or Download precompiled pdo_sqlsrv extension binaries
RUN sudo apt-get install -y php7.0-cli \
    &&wget -nv "https://github.com/Microsoft/msphpsql/releases/download/4.0.8-Linux/Ubuntu15.tar" \
    && tar -xf Ubuntu15.tar \
    && sudo cp -v ./Ubuntu15/php_pdo_sqlsrv_7_nts.so /usr/lib/php/20151012/pdo_sqlsrv.so \
    && printf "; priority=20\nextension=pdo_sqlsrv.so" \
    | sudo tee /etc/php/7.0/mods-available/pdo_sqlsrv.ini \
    && sudo phpenmod pdo_sqlsrv \
    && php --rextinfo pdo_sqlsrv \
    && sudo phpdismod pdo_sqlsrv \
    && sudo rm -f /usr/lib/php/20151012/pdo_sqlsrv.so

Installing pdo_sqlsrv using Docker image php:7.1

Originally created by Remco

    FROM php:7.1-apache
    
    RUN apt-get install -y whiptail \
        unixodbc libgss3 odbcinst devscripts debhelper dh-exec dh-autoreconf libreadline-dev libltdl-dev \
        && dget -u -x http://http.debian.net/debian/pool/main/u/unixodbc/unixodbc_2.3.1-3.dsc \
        && cd unixodbc-*/ \
        && dpkg-buildpackage -uc -us -B \
        && cp -v ./exe/odbc_config /usr/local/bin/
    
    RUN printf '#!/bin/bash\nif [ "$*" == "-p" ]; then echo "x86_64"; else /bin/uname "$@"; fi' \
        | tee /usr/local/bin/uname \
        && chmod +x /usr/local/bin/uname
    
    RUN apt-get install -y wget \
        && wget -nv -O msodbcsql-13.0.0.0.tar.gz \
        "https://meetsstorenew.blob.core.windows.net/contianerhd/Ubuntu%2013.0%20Tar/msodbcsql-13.0.0.0.tar.gz?st=2016-10-18T17%3A29%3A00Z&se=2022-10-19T17%3A29%3A00Z&sp=rl&sv=2015-04-05&sr=b&sig=cDwPfrouVeIQf0vi%2BnKt%2BzX8Z8caIYvRCmicDL5oknY%3D" \
        && tar -xf msodbcsql-13.0.0.0.tar.gz \
        && cd msodbcsql-*/ \
        && ldd lib64/libmsodbcsql-13.0.so.0.0 \
        && ./install.sh install --accept-license \
        && ls -l /opt/microsoft/msodbcsql/ \
        && odbcinst -q -d -n "ODBC Driver 13 for SQL Server"
    
    RUN apt-get install -y apt-transport-https lsb-release ca-certificates \
        && wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \
        && echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list \
        && apt-get update
        
    RUN apt-get install -y unixodbc-dev php7.1-dev php-pear \
        && pecl channel-update pecl.php.net \
        && pecl install pdo_sqlsrv-4.1.6.1 \
        && printf "; priority=20\nextension=/usr/lib/php/20160303/pdo_sqlsrv.so" | tee /etc/php/7.1/mods-available/pdo_sqlsrv.ini \
        && echo "extension=pdo_sqlsrv.so" > /usr/local/etc/php/conf.d/pdo_sqlsrv.ini
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.