Php – install sql server driver on ubuntu

PHPsql server

I want to connect to sql server database which is placed on a remote server while my php code has been installed on an ubuntu server. I found that it needs to install sqlsrv driver or mssql driver before connecting. How can I install the requirement(s) in advanced?

Best Answer

Install PHP extension in OS: apt-get install php5-sybase, restart Apache or PHP-FPM (depending on your SAPI). Make sure the newly installed PDO driver is loaded (should be enabled automatically, check for output line php5_invoke: Enable module pdo_dblib for [your SAPI here]). This will also install all dependencies. Now you can use mssql: DSNs in PDO, as presented in PHP manual.

There's another PDO driver for MSSQL, but it only works under Windows.

You can also use PDO with ODBC.