Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreiTelteu/1b3a739f7b971b7cd7643adda374197d to your computer and use it in GitHub Desktop.
Save AndreiTelteu/1b3a739f7b971b7cd7643adda374197d to your computer and use it in GitHub Desktop.

You can follow microsoft's official instalation steps, however if you have multiple php instalations (I have php7.4 and 7.3 installed on my laravel forge server) you need to specify what version to build the extension with.

# make sure you have this installed:
sudo apt-get install -y unixodbc-dev

# elevate as root
sudo su
pecl -d php_suffix=7.3 install sqlsrv
pecl -d php_suffix=7.3 install pdo_sqlsrv
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.3/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.3/mods-available/pdo_sqlsrv.ini
phpenmod -v 7.3 sqlsrv pdo_sqlsrv

Check with php -m | grep sql If you see pdo_sqlsrv and sqlsrv in that list you have the extension installed in php-cli. You need a restart to php-fpm or apache and you're done. service php7.3-fpm restart

If you installed it wrong and want a fresh start run:

pecl uninstall -r sqlsrv
pecl uninstall -r pdo_sqlsrv
# or manual remove
rm -rf /etc/php/7.3/mods-available/sqlsrv.ini /etc/php/7.3/mods-available/pdo_sqlsrv.ini

If you see error SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server ... follow this instalation tutorial to install ODBC Driver: https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017#ubuntu18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment