SQLSRV PHP extension for Plesk PHP 8.0 - 8.3

Foreword

The PHP Microsoft SQL Extension (sqlsrv) can be used to establish a native MSSQL connection to a Microsoft SQL Server.


Before installing PHP extensions, a server snapshot should be created so that you can undo the installation with just a few clicks in the event of an error. Please read the following article: Server snapshots



Installation

Additional packages are required for the installation under PHP 8.0, 8.1, 8.2 and 8.3. These can be installed using the following SSH command:


apt install plesk-php80-dev plesk-php81-dev plesk-php82-dev plesk-php83-dev apt-transport-https gcc g++ unixodbc unixodbc-dev make


Next, the msodbcsql17 (PHP 8.0) or alternatively msodbcsql18 (PHP 8.1 - 8.3) package from Microsoft must be installed:


PHP 8.1 - 8.3

curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg
curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql18


PHP 8.0

curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg
curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql17


The PHP extension SQLSRV must be installed for each PHP version:


PHP 8.1 - PHP 8.3

/opt/plesk/php/8.1/bin/pecl install sqlsrv pdo_sqlsrv
/opt/plesk/php/8.2/bin/pecl install sqlsrv pdo_sqlsrv
/opt/plesk/php/8.3/bin/pecl install sqlsrv pdo_sqlsrv


PHP 8.0

/opt/plesk/php/8.0/bin/pecl install pdo_sqlsrv-5.11.1
echo "extension=pdo_sqlsrv.so" > /opt/plesk/php/8.0/etc/php.d/pdo_sqlsrv.ini
/opt/plesk/php/8.0/bin/pecl install sqlsrv-5.11.1
echo "extension=sqlsrv.so" > /opt/plesk/php/8.0/etc/php.d/sqlsrv.ini


To enable the new configuration via the Plesk web interface, the PHP handlers must be reinitialized:


plesk bin php_handler --reread
plesk sbin packagemng -sdf


The PHP handlers must then be restarted so that the SQLSRV extension can be used:


Warning: Restarting the PHP modules will terminate and restart all running PHP processes. If the installation is carried out on a production system, we recommend making this change at night.


systemctl restart plesk-php80-fpm
systemctl restart plesk-php81-fpm
systemctl restart plesk-php82-fpm
systemctl restart plesk-php83-fpm