| title | Step 1: Configure Environment for PHP | |
|---|---|---|
| description | Step 1 of this getting started guide involves installing PHP, the Microsoft ODBC Driver for SQL Server, and configuring your development environment. | |
| author | David-Engel | |
| ms.author | davidengel | |
| ms.reviewer | randolphwest | |
| ms.date | 03/25/2026 | |
| ms.service | sql | |
| ms.subservice | connectivity | |
| ms.topic | how-to | |
| ms.custom |
|
[!INCLUDE Driver_PHP_Download]
To connect to SQL Server from a PHP application, you need the following components installed in this order:
-
PHP runtime: Download and install PHP from php.net (Windows) or use your system package manager (Linux/macOS).
-
Microsoft ODBC Driver for SQL Server: The PHP drivers require the ODBC driver. Download it from Download ODBC Driver for SQL Server.
-
Microsoft Drivers for PHP for SQL Server: Download the drivers from Download the Microsoft Drivers for PHP for SQL Server. For more information on version compatibility, see System requirements for the Microsoft Drivers for PHP for SQL Server.
-
Web server (optional): Configure IIS (Windows) or Apache/Nginx (Linux/macOS) if you're building web applications.
-
Download and install PHP — use the Thread Safe (TS) version for IIS, or Non-Thread Safe (NTS) for Apache or CLI.
-
Download and install the ODBC Driver for SQL Server.
-
Download the Microsoft Drivers for PHP for SQL Server and extract the
.dllfiles to your PHP extensions directory. -
Enable the driver by adding the following lines to your
php.inifile:extension=php_sqlsrv.dll extension=php_pdo_sqlsrv.dll
-
Verify the installation by running
php -mand checking thatsqlsrvandpdo_sqlsrvappear in the list.
For detailed instructions, see Loading the Microsoft Drivers for PHP for SQL Server. To configure IIS, see Download the Microsoft Drivers for PHP for SQL Server.
For step-by-step instructions on installing PHP, the ODBC driver, and the PHP drivers on Linux and macOS, see Linux and macOS Installation Tutorial for the Microsoft Drivers for PHP for SQL Server.