README.md
The code samples are available here
Aptfile file is mandatory. Create a file called Aptfile in your project root folder, then copy its content from one of these (pick the one matching your driver/Ubuntu version), or download it directly:
It must be set,
$ heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://github.com/heroku-softtrends/mssql-server-drivers-for-php/raw/main/5.13.3/ubuntu/24.04/php/8.3/nts/packages.json" -a <heroku_app_name>
$ heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://github.com/heroku-softtrends/mssql-server-drivers-for-php/raw/main/5.13.3/ubuntu/24.04/php/8.4/nts/packages.json" -a <heroku_app_name>
$ heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://github.com/heroku-softtrends/mssql-server-drivers-for-php/raw/main/5.13.3/ubuntu/24.04/php/8.5/nts/packages.json" -a <heroku_app_name>
$ heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://github.com/heroku-softtrends/mssql-server-drivers-for-php/raw/main/5.13.3/ubuntu/26.04/php/8.4/nts/packages.json" -a <heroku_app_name>
$ heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://github.com/heroku-softtrends/mssql-server-drivers-for-php/raw/main/5.13.3/ubuntu/26.04/php/8.5/nts/packages.json" -a <heroku_app_name>
$ heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://github.com/heroku-softtrends/mssql-server-drivers-for-php/raw/main/5.11.1/ubuntu/22.04/php/8.1/nts/packages.json" -a <heroku_app_name>
$ heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://github.com/heroku-softtrends/mssql-server-drivers-for-php/raw/main/5.11.1/ubuntu/22.04/php/8.2/nts/packages.json" -a <heroku_app_name>
$ heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://github.com/heroku-softtrends/mssql-server-drivers-for-php/raw/main/5.10.0/ubuntu/20.04/php/8.1/nts/packages.json" -a <heroku_app_name>
$ heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://github.com/heroku-softtrends/mssql-server-drivers-for-php/raw/main/5.10.0/ubuntu/20.04/php/8.0/nts/packages.json" -a <heroku_app_name>
$ heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://github.com/heroku-softtrends/mssql-server-drivers-for-php/raw/main/5.10.0/ubuntu/20.04/php/7.4/nts/packages.json" -a <heroku_app_name>
Add required dependencies(SQLSRV and PDO_SQLSRV drivers) to composer.json file
{
"require": {
"php": "~8.3.0",
"ext-sqlsrv": "^5.13",
"ext-pdo_sqlsrv": "^5.13"
}
}
{
"require": {
"php": "~8.4.0",
"ext-sqlsrv": "^5.13",
"ext-pdo_sqlsrv": "^5.13"
}
}
{
"require": {
"php": "~8.5.0",
"ext-sqlsrv": "^5.13",
"ext-pdo_sqlsrv": "^5.13"
}
}
{
"require": {
"php": "~8.1.0",
"ext-sqlsrv": "^5.11",
"ext-pdo_sqlsrv": "^5.11"
}
}
{
"require": {
"php": "~8.2.0",
"ext-sqlsrv": "^5.11",
"ext-pdo_sqlsrv": "^5.11"
}
}
{
"require": {
"php": "~8.1.0",
"ext-sqlsrv": "^5.10",
"ext-pdo_sqlsrv": "^5.10"
}
}
{
"require": {
"php": "~8.0.0",
"ext-sqlsrv": "^5.10",
"ext-pdo_sqlsrv": "^5.10"
}
}
{
"require": {
"php": "~7.4.0",
"ext-sqlsrv": "^5.10",
"ext-pdo_sqlsrv": "^5.10"
}
}
After adding new dependencies to composer.json file, must be updated by running:
$ composer update --ignore-platform-reqs
Finally the composer.lock file will look like,
{
"platform": {
"php": "~8.3.0",
"ext-sqlsrv": "^5.13",
"ext-pdo_sqlsrv": "^5.13"
}
}
{
"platform": {
"php": "~8.4.0",
"ext-sqlsrv": "^5.13",
"ext-pdo_sqlsrv": "^5.13"
}
}
{
"platform": {
"php": "~8.5.0",
"ext-sqlsrv": "^5.13",
"ext-pdo_sqlsrv": "^5.13"
}
}
{
"platform": {
"php": "~8.1.0",
"ext-pdo_sqlsrv": "^5.11",
"ext-sqlsrv": "^5.11"
}
}
{
"platform": {
"php": "~8.2.0",
"ext-sqlsrv": "^5.11",
"ext-pdo_sqlsrv": "^5.11"
}
}
{
"platform": {
"php": "~8.1.0",
"ext-pdo_sqlsrv": "^5.10",
"ext-sqlsrv": "^5.10"
}
}
{
"platform": {
"php": "~8.0.0",
"ext-sqlsrv": "^5.10",
"ext-pdo_sqlsrv": "^5.10"
}
}
{
"platform": {
"php": "~7.4.0",
"ext-sqlsrv": "^5.10",
"ext-pdo_sqlsrv": "^5.10"
}
}
https://github.com/heroku/heroku-buildpack-apt.git
https://github.com/heroku/heroku-buildpack-php.git
https://github.com/heroku-softtrends/heroku-php-sqlsrv-buildpack.git
$ git init
$ heroku git:remote -a <app_name>
$ git add --all
$ git commit -m "First commit"
$ git push heroku master
Set the stack explicitly if you're not using Heroku's current default (heroku-24):
$ heroku stack:set <heroku-20|heroku-22|heroku-24|heroku-26> -a <app_name>
$ heroku open -a <heroku_app_name>
bin/compile: now fails loudly with a clear message instead of
silently producing an empty MS_ODBC_VERSION if .apt/opt/microsoft
is missing (e.g. buildpack order wrong, or Aptfile didn't install
msodbcsql). If both msodbcsql17 and msodbcsql18 end up installed at
once, it picks the higher version deterministically; set
MSODBCSQL_VERSION=17 as a config var to force the other one. It also
falls back from lib64/ to lib/ if a future package ever changes that
layout, and copies .profile.d/configure-odbc.sh by resolving its own
path instead of assuming a particular working directory..profile.d/configure-odbc.sh: fixed a real bug — it used to glob
.apt/usr/lib/* and take whatever file happened to sort first, which is
not necessarily the ODBC driver once apt has also installed unixODBC
and its dependencies into that same directory. It now globs
libmsodbcsql-* specifically. It also fixes ODBCINI, which previously
pointed at a directory (invalid — unixODBC expects ODBCINI to be a
file path) instead of odbc.ini itself; ODBCSYSINI correctly stays a
directory./opt/microsoft/msodbcsql<N>/lib64/...
package layout these scripts rely on is the same across every Ubuntu
version Microsoft ships msodbcsql for, so no stack-specific branching
was needed in the scripts themselves — only the README's Aptfile/
packages.json links needed the new 5.13.3 entries above.msphpsql has not announced official
Ubuntu 26.04 support as of driver 5.13.3, and msodbcsql17 isn't
published for 26.04 at all — only msodbcsql18 is. See the 26.04 notes
in the mssql-server-drivers-for-php README for the full reasoning. Treat the
heroku-26 path here as untested until you've deploy-tested it yourself.ODBCINI bug above are real regardless of stack), but please
verify a real git push heroku build + heroku run php -m /
heroku run php -r "var_dump(new PDO(...))" before relying on this in
production.Heroku platform dependencies installation
For new applications:
For existing applications: