SQLSRV PHP extension for Plesk PHP 7

Please note that the following instructions can only be used for Plesk Obsidian under Linux Debian 9.


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. Server snapshots


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

Installation

Additional packages are required for installation under PHP 7.2, 7.3 and 7.4. These can be installed using the following SSH command:


apt install plesk-php72-dev plesk-php73-dev plesk-php74-dev apt-transport-https gcc g++ unixodbc unixodbc-dev make


Next, the msodbcsql17 package from Microsoft must be installed:


curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/debian/9/prod.list > /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:


/opt/plesk/php/7.2/bin/pecl install sqlsrv pdo_sqlsrv
/opt/plesk/php/7.3/bin/pecl install sqlsrv pdo_sqlsrv
/opt/plesk/php/7.4/bin/pecl install sqlsrv pdo_sqlsrv


After successful installation, the extension must be added to the PHP configuration:


# PHP 7.2
echo "extension=sqlsrv.so" > /opt/plesk/php/7.2/etc/php.d/sqlsrv.ini
echo "extension=pdo_sqlsrv.so" > /opt/plesk/php/7.2/etc/php.d/pdo_sqlsrv.ini

# PHP 7.3
echo "extension=sqlsrv.so" > /opt/plesk/php/7.3/etc/php.d/sqlsrv.ini
echo "extension=pdo_sqlsrv.so" > /opt/plesk/php/7.3/etc/php.d/pdo_sqlsrv.ini

# PHP 7.4
echo "extension=sqlsrv.so" > /opt/plesk/php/7.4/etc/php.d/sqlsrv.ini
echo "extension=pdo_sqlsrv.so" > /opt/plesk/php/7.4/etc/php.d/pdo_sqlsrv.ini


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


plesk bin php_handler --reread


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-php72-fpm
systemctl restart plesk-php73-fpm
systemctl restart plesk-php74-fpm