Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lumethys's avatar

MSSQL Server (SQLSRV) on Fly.io

So i'm working on a deploy of a hobby project on Fly.io, only thing is, it use a MSSQL server as the database, which mean i need to install sqlsrv and pdo_sqlsrv on the Fly.io's docker container.

Problem is, they use their custom docker image as the base image, which doesnt include pecl or the docker-php-ext-xxxx stuffs.

I tried using COPY -from :

COPY --from=php:8.2-fpm /usr/local/bin/docker-php-ext-install /usr/bin/docker-php-ext-install
COPY --from=php:8.2-fpm /usr/local/bin/docker-php-source /usr/bin/docker-php-source
COPY --from=php:8.2-fpm /usr/local/bin/docker-php-ext-enable /usr/bin/docker-php-ext-enable
COPY --from=php:8.2-fpm /usr/local/bin/docker-php-ext-configure /usr/bin/docker-php-ext-configure
# COPY --from=php:8.2-fpm /usr/local/bin/phpize /usr/local/bin/phpize
COPY --from=php:8.2-fpm /usr/src/php.tar.xz /usr/src/php.tar.xz

to get the helper, along with this method to download the required files. But it seem like the installation of PHP of Fly.io and the official php image was a bit different and phpize failed to find the build path

Then, i tried install pecl via php-dev and php-pear

RUN apt-get update && apt-get install -y php-xml php-dev php-pear

But somehow this also doesnt play nice with the base image.

Then, i tried, to use the php docker-php-ext-xxxx, but instead of using their phpize, i use pecl's. This lead to a successful build, but there the final build sdtill doesnt recogize sqlsrv and pdo_sqlsrv

And this is driving me crazy. Has anyone attempted the same and succeed?

0 likes
1 reply
Lumethys's avatar
Lumethys
OP
Best Answer
Level 5

Found the solution

This is the default Laravel Dockerfile

# syntax = docker/dockerfile:experimental

# Default to PHP 8.2, but we attempt to match
# the PHP version from the user (wherever `flyctl launch` is run)
# Valid version values are PHP 7.4+
ARG PHP_VERSION=8.2
ARG NODE_VERSION=18
FROM fideloper/fly-laravel:${PHP_VERSION} as base

# PHP_VERSION needs to be repeated here
# See https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PHP_VERSION

LABEL fly_launch_runtime="laravel"

### ====>  We will add the sqlsrv driver here

# copy application code, skipping files based on .dockerignore
COPY . /var/www/html

...

this snippet will do the job:

### PHP sqlsrv ext
#pecl
RUN apt-get update && apt-get install -y php-xml
RUN apt-get update && apt-get install -y php-dev php-pear
RUN apt-get update && apt-get install -y mcrypt php-mbstring php-mysql

ENV ACCEPT_EULA=Y

RUN apt-get update && apt-get install -y xz-utils
RUN apt-get update && apt-get install -y gnupg2
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list #this is version - specific, Flyio's image is ubuntu 20.04
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get -y --no-install-recommends install msodbcsql18 unixodbc-dev #specify the version, i use version 18: msodbcsql18
# install ODBC Driver
RUN apt-get install -y mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN exec bash

# install driver sqlsrv
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv

#
RUN printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.2/mods-available/sqlsrv.ini
RUN printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.2/mods-available/pdo_sqlsrv.ini
RUN phpenmod -v 8.2 sqlsrv pdo_sqlsrv

Please or to participate in this conversation.