This topic is locked

Connecting to SQL Server from PHP running on a Linux server

6/4/2021 4:44:44 PM
PHPRunner Tips and Tricks
admin

While this is not the most traditional setup, connecting from LInux server's PHP to SQL Server database is possible and here are the steps.

  • Linux Ubuntu 18.04 Server
  • PHP 8.0.5
  • Apache 2.4.29
  • MS SQL Server - 2016 SP2

Configure ODBC driver on Linux server

Testing your ODBC driver installation

The key is to execute the following command on your Ubuntu server:
sudo apt-get install -y php-odbc

Now in PHPRunner you can add a new database connection and use the following connection string:
Provider=SQLOLEDB;Server=<MSSQL IP / Hostname>;Uid=myloginname;Pwd=mypassword;Database=myMSSQLdatabase

Dalkeith 6/7/2021

Good timing I tried this the other day trying to link to an SQL Azure database but failed because no odbc on the linux server. If I can get it to work it will reduce my hosting charges.

Dalkeith 6/7/2021

I should add that if you are using Microsoft Azure, a phprunner application hosted within a linux hosted web app linked to SQL Azure database, performance is fantastic. I believe they have the odbc driver pre-installed when you set up a linux web application host as I didn't have to do this configuration to make it work just connected through PHPrunners configuration and it was go.