I'm attempting to setup the Microsoft ODBC Driver on platform.sh so that the PDO_SQLSRV and SQLSRV PHP extensions are available to me. apt and other sudo commands are limited. However, during the build I can set environment variables such as LD_LIBRARY_PATH.
Here is what I have tried so far.
export LD_LIBRARY_PATH="($pwd):$LD_LIBRARY_PATH"
and LD_LIBRARY_PATH="($pwd):$LD_LIBRARY_PATH" /usr/sbin/php-fpm7.0
Still, I get the following error:
SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 13
for SQL Server to communicate with SQL Server. Access the following
URL to download the ODBC Driver 13 for SQL Server for x86:
http://go.microsoft.com/fwlink/?LinkId=163712
Update
All dependencies are met when I execute LD_LIBRARY_PATH=$(pwd) ldd libmsodbcsql-13.1.so.4.0
. However, when I launch with LD_LIBRARY_PATH="$(pwd):$LD_LIBRARY_PATH" /usr/sbin/php-fpm7.0
I still see the error shown above.
To install the ODBC driver, you need administrator-level privileges so that the driver can be installed in the C:\Program Files directory.
My guess is that your extension is linked to the wrong libraries.
That said, you don't need a custom extension for that. You can just add this to your .platform.app.yaml
:
runtime:
extensions:
- mssql
See this page for more information.
Use FreeTDS for your MSSQL driver instead. You will ideally need sudo privileges. Although it is possible to have user specific ODBC configuration files, you would still need to install the base software if it's not already been done.
sudo apt-get install freetds-common freetds-bin unixodbc tdsodbc php5-odbc php5-sybase
Add a connection to: /etc/freetds/freetds.conf
[global]
text size = 64512
[my_connection]
host = SQL_HOSTNAME
port = SQL PORT - possibly 1433
tds_version = 7.2
encryption = required
Add FreeTDS to your ODBC driver list: /etc/odbcinst.ini
[odbc]
Description = ODBC driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
[FreeTDS]
Description = FreeTDS
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Finally add the FreeTDS connection to your ODBC config: /etc/odbc.ini
The ServerName must match the one used in FreeTDS
[my_connection]
Driver = FreeTDS
Description = Uses FreeTDS configuration settings defined in /etc/freetds/freetds.conf
Servername = my_connection
TDS_Version = 7.2
[Default]
Driver = FreeTDS
Now you will be able to use PDO with the ODBC or FreeTDS drivers.
Using FreeTDS directly
$pdo = new PDO($'dblib:host=my_connection', 'username', 'password');
Or using ODBC via FreeTDS
$pdo = new PDO('odbc=my_connection', 'username', 'password');
You might find both drivers have slightly different characteristics so use the one which is most reliable for the queries you are using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With