Chỉnh sửa

Chia sẻ qua


Step 1: Configure environment for PHP development

Download PHP driver

To connect to SQL Server from a PHP application, you need the following components installed in this order:

  1. PHP runtime: Download and install PHP from php.net (Windows) or use your system package manager (Linux/macOS).

  2. Microsoft ODBC Driver for SQL Server: The PHP drivers require the ODBC driver. Download it from Download ODBC Driver for SQL Server.

  3. 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.

  4. Web server (optional): Configure IIS (Windows) or Apache/Nginx (Linux/macOS) if you're building web applications.

Windows

  1. Download and install PHP — use the Thread Safe (TS) version for IIS, or Non-Thread Safe (NTS) for Apache or CLI.

  2. Download and install the ODBC Driver for SQL Server.

  3. Download the Microsoft Drivers for PHP for SQL Server and extract the .dll files to your PHP extensions directory.

  4. Enable the driver by adding the following lines to your php.ini file:

    extension=php_sqlsrv.dll
    extension=php_pdo_sqlsrv.dll
    
  5. Verify the installation by running php -m and checking that sqlsrv and pdo_sqlsrv appear 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.

Linux and macOS

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.