Created
October 16, 2023 14:56
-
-
Save Patabugen/2fdd41ce079b2602ec922d384e65a03b to your computer and use it in GitHub Desktop.
Setup pdo_sqlsrv for PHP 8.2 in ubuntu:22.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# I use this to setup my Laravel 10 (sail) docker container to setup PDO_Sqlsrv | |
# Let pecl auto-configure our php.ini | |
pear config-set php_ini /etc/php/8.1/cli/php.ini | |
# Setup PHP to be able to connect to SQLServer. | |
# From here: https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver16 | |
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - | |
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list > /etc/apt/sources.list.d/mssql-release.list | |
apt-get update | |
ACCEPT_EULA=Y apt-get install -y msodbcsql18 | |
# optional: for bcp and sqlcmd | |
ACCEPT_EULA=Y apt-get install -y mssql-tools18 | |
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc | |
source ~/.bashrc | |
# optional: for unixODBC development headers | |
apt-get install -y unixodbc-dev | |
pecl install sqlsrv | |
pecl install pdo_sqlsrv | |
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.1/mods-available/sqlsrv.ini | |
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.1/mods-available/pdo_sqlsrv.ini | |
phpenmod -v 8.1 sqlsrv pdo_sqlsrv | |
# We're ending up with two extra extension= entries in php.ini. Rather than figure out why... | |
# I'm just going to strip them out for now to avoid the errors they give. | |
sed -i '1 s/extension="pdo_sqlsrv.so"//g' /etc/php/8.1/cli/php.ini | |
sed -i '2 s/extension="sqlsrv.so"//g' /etc/php/8.1/cli/php.ini |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment