Setup Apache2 with PHP 5.6 or 7 on windows with MS SQL module

Forum for you who has PHP installation issues

Moderators: gesf, Michalio

Post Reply

Hi everyone,

Does anybody try to install and setup Microsoft SQL module for Apache on Windows?

I found couple tutorials on the web but when i open php info page sqlsrv module was not listed/loaded.

Code: Select all
I have small project and i need to read some data from SQL server instead of MySQL.

Thanks in advance!

I will post reply to my self :)

How to setup Microsoft SQL Extension for PHP and Apache on Windows

Download Microsoft Drivers for PHP for SQL Server from fallowing link:

Code: Select all
Depends of the PHP version you use on the Apache web server, download properMicrosoft Driver version

Code: Select all
PHP Version 7.2 > SQl Driver 5.2 (7.2.1+)
PHP Version 7.1 > SQl Driver 5.2 (7.1.0+) or 4.3
PHP Version 7.0 > SQl Driver 5.2 (7.0.0+) or 4.3 or 4.0
PHP Version 5.6 > SQl Driver 3.2 (5.6.4+)
PHP Version 5.5 > SQl Driver 5.2 (5.5.16++) or 3.1

Extract downloaded package

On the phpinfo page, check row Architecture of the apache server.
If your architecture x86 then use _x86 dll's if architecture is x64 then use _x64 dll's (don't look your windows architecture!!)

[PHP 7.2 example] - for XAMPP webserver

Copy files php_pdo_sqlsrv_72_ts_x86.dll and php_sqlsrv_72_ts_x86.dll from extracted folders to c:\xampp\php\ext
then configure c:\xampp\php\php.ini file
enable extensions (or add lines if missing)


restart apache service.

Download and install Microsoft® ODBC Driver 13 for SQL Server (Windows) from fallowing link:

Code: Select all
Download architecture version of the ODBC driver according to your windows architecture x86 or x64 (not of the architecture of the Apache and PHP from the begining of this manual!)

English\X64\msodbcsql.msi 4.1 MB
English\X86\msodbcsql.msi 2.6 MB

After you install ODBC driver, go to your apache root, create file sql_serverinfo.php, edit it and put fallowing code:

Code: Select all

$conn = sqlsrv_connect( $serverName);
if( $conn === false ) {
     die( print_r( sqlsrv_errors(), true));

$server_info = sqlsrv_server_info( $conn);
if( $server_info )
    foreach( $server_info as $key => $value) {
       echo $key.": ".$value."<br />";
} else {
      die( print_r( sqlsrv_errors(), true));
Save file and open in in browser

Code: Select all

you should get returned values from MS SQL Server:

CurrentDatabase: master
SQLServerVersion: 12.00.4100

And it's done!

You have successfully configured your apache and php on windows to connect on Microsoft SQL Server database.

To create queries use fallowing instructions from PHP

Code: Select all
I hope this manual will be useful for someone.
Post Reply