Debian 10 – msphpsql – php 7.3 to MS SQL Error 0x2746

Installed the PHP driver for MS SQL on a vanilla Debian 10 VM, using:

# Escalate
sudo su

# PHP

apt-get install curl apt-transport-https
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
apt-get update
apt-get install -y php7.3 php7.3-dev php7.3-xml php7.3-intl
sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
locale-gen
pecl install sqlsrv
pecl 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

# ODBC

curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql17
# optional: for bcp and sqlcmd
ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

As per the docs. Then connecting gives this error in PHP:

Failed to connect to database: [0] SQLSTATE: 08001 code: 10054 message: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746[1] SQLSTATE: 08001 code: 10054 message: [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection

And this on the server (SQL Server 2012):

A fatal alert was generated and sent to the remote endpoint. This may result in termination of the connection. The TLS protocol defined fatal error code is 40. The Windows SChannel error state is 1205.

Lots of chat about this on the forums ( https://github.com/microsoft/msphpsql/issues/1021 ) but this comment by miktea is the key:

Modify /etc/ssl/openssl.cnf config file:

CipherString = DEFAULT@SECLEVEL=2 
to 
CipherString = DEFAULT@SECLEVEL=1

Thanks https://stackoverflow.com/questions/57265913/error-tcp-provider-error-code-0x2746-during-the-sql-setup-in-linux-through-te/59503719#59503719

About: Rob