Skip to main content This browser is no longer supported. Show
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Linux and macOS Installation Tutorial for the Microsoft Drivers for PHP for SQL Server
In this articleThe following instructions assume a clean environment and show how to install PHP 8.1, the Microsoft ODBC driver, the Apache web server, and the Microsoft Drivers for PHP for SQL Server on Ubuntu, Red Hat, Debian, Suse, Alpine, and macOS. These instructions advise installing the drivers using PECL, but you can also download the prebuilt binaries from the Microsoft Drivers for PHP for SQL Server GitHub project page and install them following the instructions in Loading the Microsoft Drivers for PHP for SQL Server. For an explanation of extension loading and why we do not add the extensions to php.ini, see the section on loading the drivers. The following instructions install PHP 8.1 by default using Also included are instructions for installing the PHP FastCGI Process Manager, PHP-FPM, on Ubuntu. PHP-FPM is needed if you're using the nginx web server instead of Apache. While these instructions contain commands to install both SQLSRV and PDO_SQLSRV drivers, the drivers can be installed and function independently. Users comfortable with customizing their configuration can adjust these instructions to be specific to SQLSRV or PDO_SQLSRV. Both drivers have the same dependencies except where noted below. Installing on UbuntuUbuntu versions 18.04, 20.04, 21.04 and 21.10 are supported. Note To install PHP 7.4 or 8.0, replace 8.1 with 7.4 or 8.0 in the following commands. Step 1. Install PHP (Ubuntu)
Step 2. Install prerequisites (Ubuntu)Install the ODBC driver for Ubuntu by following the instructions on the Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the Step 3. Install the PHP drivers for Microsoft SQL Server (Ubuntu)
If there is only one PHP version in the system, then the last step can be simplified to Step 4. Install Apache and configure driver loading (Ubuntu)
Step 5. Restart Apache and test the sample script (Ubuntu)
To test your installation, see Testing your installation at the end of this document. Installing on Ubuntu with PHP-FPMUbuntu versions 18.04, 20.04, 21.04 and 21.10 are supported. Note To install PHP 7.4 or 8.0, replace 8.1 with 7.4 or 8.0 in the following commands. Step 1. Install PHP (Ubuntu with PHP-FPM)
Verify the status of the PHP-FPM service by running:
Step 2. Install prerequisites (Ubuntu with PHP-FPM)Install the ODBC driver for Ubuntu by following the instructions on the
Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the Step 3. Install the PHP drivers for Microsoft SQL Server (Ubuntu with PHP-FPM)
If there is only one PHP version in the system, then the last step can be simplified to Verify that
Restart the PHP-FPM service:
Step 4. Install and configure nginx (Ubuntu with PHP-FPM)
To configure nginx, you must edit the
Next, uncomment and modify the section following
Step 5. Restart nginx and test the sample script (Ubuntu with PHP-FPM)
To test your installation, see Testing your installation at the end of this document. Installing on Red HatRed Hat versions 7 and 8 are supported. Step 1. Install PHP (Red Hat)To install PHP on Red Hat 7, run the following commands: Note To install PHP 7.4 or 8.0, replace remi-php81 with remi-php74 or remi-php80 respectively in the following commands.
To install PHP on Red Hat 8, run the following commands: Note To install PHP 7.4 or 8.0, replace remi-8.1 with remi-7.4 or remi-8.0 respectively in the following commands.
Step 2. Install prerequisites (Red Hat)Install the ODBC driver for Red Hat 7 or 8 by following the instructions on the Install the Microsoft
ODBC driver for SQL Server (Linux). Make sure to also install the Step 3. Install the PHP drivers for Microsoft SQL Server (Red Hat)
You can alternatively install from the Remi repo:
Step 4. Install Apache (Red Hat)
SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to databases through SELinux, run the following command:
Step 5. Restart Apache and test the sample script (Red Hat)
To test your installation, see Testing your installation at the end of this document. Installing on DebianDebian versions 9, 10 and 11 are supported. Note To install PHP 7.4 or 8.0, replace 8.1 in the following commands with 7.4 or 8.0. Step 1. Install PHP (Debian)
Step 2. Install prerequisites (Debian)Install the ODBC driver for Debian by following the instructions on the
Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the You may also need to generate the correct locale to get PHP output to display correctly in a browser. For example, for the en_US UTF-8 locale, run the following commands:
You may need to add Step 3. Install the PHP drivers for Microsoft SQL Server (Debian)
If there is only one PHP version in the system, then the last step can be simplified to Step 4. Install Apache and configure driver loading (Debian)
Step 5. Restart Apache and test the sample script (Debian)
To test your installation, see Testing your installation at the end of this document. Installing on SuseSuse Enterprise Linux versions 12 and 15 are supported. Note In the following instructions, replace Note Packages for PHP 7.4 or above are not available for Suse 12, as of today. Step 1. Install PHP (Suse)
Step 2. Install prerequisites (Suse)Install the ODBC driver for Suse by following the instructions on the Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the Step 3. Install the PHP drivers for Microsoft SQL Server (Suse)
Step 4. Install Apache and configure driver loading (Suse)
Step 5. Restart Apache and test the sample script (Suse)
To test your installation, see Testing your installation at the end of this document. Installing on AlpineAlpine versions 3.13, 3.14 and 3.15 are supported. Note PHP 8.1 or above may be available from testing or edge repositories for Alpine. You can instead compile PHP from source. Step 1. Install PHP (Alpine)PHP packages for Alpine can be found in the
Then run:
Step 2. Install prerequisites (Alpine)Install the ODBC driver for Alpine by following the instructions on the Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the Step 3. Install the PHP drivers for Microsoft SQL Server (Alpine)
Step 4. Install Apache and configure driver loading (Alpine)
Step 5. Restart Apache and test the sample script (Alpine)
To test your installation, see Testing your installation at the end of this document. Installing on macOSMacOS versions 10.15 (Catalina), 11.0 (Big Sur), and 12.0 (Monterey) are supported. If you do not already have it, install brew as follows:
Note To install PHP 7.4 or 8.0, replace with or respectively in the following commands. Step 1. Install PHP (macOS)
PHP should now be in your path. Run
If using Apple M1 ARM64, you might need to set the path:
Step 2. Install prerequisites (macOS)Install the ODBC driver for macOS by following the instructions on the Install the Microsoft ODBC driver for SQL Server (macOS). Note If using Apple M1 ARM64 hardware, please install Microsoft ODBC driver 17.8+ directly without using the emulator Rosetta 2. In addition, you may need to install the GNU make tools:
Step 3. Install the PHP drivers for Microsoft SQL Server (macOS)
If using Apple M1 ARM64, do the following instead:
Step 4. Install Apache and configure driver loading (macOS)Note The latest macOS 11.0 Big Sur comes with Apache 2.4 pre-installed, but Apple has also removed some required scripts. The solution is to install Apache 2.4 via Homebrew and then configure it, but this is out of scope for this installation guide, so please check Apache or Homebrew for detailed instructions.
To find the Apache configuration file,
The following commands append the required configuration to
Step 5. Restart Apache and test the sample script (macOS)
To test your installation, see Testing your installation at the end of this document. Testing Your InstallationTo test this sample script, create a file called testsql.php in your system's document root. This path is SQLSRV example
PDO_SQLSRV example
Point your browser to
If running from the command line is successful but nothing shows in your browser, check the Apache log files. For more help, see Support resources for places to go. See AlsoGetting Started with the Microsoft Drivers for PHP for SQL Server Loading the Microsoft Drivers for PHP for SQL Server System Requirements for the Microsoft Drivers for PHP for SQL Server FeedbackSubmit and view feedback for |