Laravel and MSSQL 2014
Hello
I want my Laravel app to be able to communicate to MSSQL 2014 server. Also I want my app to live in a container. I used default Dockerfile from vendor/laravel/sail/runtimes/8.2/Dockerfile
I configured my database in the .env file, DB_CONNECTION=sqlsrv etc. I can connect to the same database on my computer using TablePlus.
In the container, in tinker I try running: DB::select('SELECT * FROM Artikel')
Response: Illuminate\Database\QueryException could not find driver (Connection: sqlsrv)
OK, necessary drivers are not installed, added this to Dockerfile:
RUN pecl channel-update pecl.php.net \
&& pecl install sqlsrv pdo_sqlsrv \
&& printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.2/mods-available/sqlsrv.ini \
&& printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.2/mods-available/pdo_sqlsrv.ini \
&& phpenmod -v 8.2 sqlsrv pdo_sqlsrv \
&& pecl clear-cache \
&& rm -rf /tmp/* /var/tmp/*
Now sail build fails:
/tmp/pear/temp/sqlsrv/shared/xplat.h:30:10: fatal error: sql.h: No such file or directory
Found out that I need unixodbc-dev package installed added this to Dockerfile:
RUN curl packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc \
&& curl packages.microsoft.com/config/ubuntu/22.04/prod.list | tee /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
&& ACCEPT_EULA=Y apt-get install -y mssql-tools18 \
&& echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc \
&& apt-get install -y unixodbc-dev
(Had to butcher the links after curl, new user, am not allowed to post links)
Now in tinker running DB::select gives me this error:
SQLSTATE[08001]: [Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: Error code 0x2746 (Connection: sqlsrv, SQL: SELECT * FROM Artikel).
I read that this issue is caused by MSSQL 2014 using OpenSSL 1.1 but Ubuntu has OpenSSL 3 installed, I tried to make Ubuntu container to use OpenSSL 1 by adding this to Dockerfile:
RUN chmod +rwx /etc/ssl/openssl.cnf
RUN sed -i 's/TLSv1.2/TLSv1/g' /etc/ssl/openssl.cnf
RUN sed -i 's/SECLEVEL=2/SECLEVEL=1/g' /etc/ssl/openssl.cnf
But that did not change anything.
Anyone has an idea how to solve the problem?
Please or to participate in this conversation.