Installing XAMPP on Windows 10 With SQLSRV Drivers

Purpose.  We are in the process of converting over to a Linux-Apache stack after hosting our PHP site on a Windows-IIS stack.  Locally, we will need to have an IIS and Apache stack running on our Windows machine for the time being until the conversion process is over.  The local machine will continue to be Windows based.

Prerequisite.  For full transparency, here are the “important” specs to my current workstation.

  • Windows 10
  • SQL (development database is not local but in Azure)
  • Maintain both IIS and Apache web servers.
  • Github Version Control
  • PHP 7.1
  • Composer Dependency Manager
  • Front-end Stack Includes: Grunt & Webpack, NPM

Step 1

Because I’m trying to match our server as best as possible, I’ve opted to install XAMPP 7.1.22 which comes with PHP 7.1.

I’ve went with the default option and unchecked MySQL, Filezilla FTP Server, Mercury Mail Server, Tomcat, and Perl.

Step 2

Now I need it’s time to map the project url to the local IP address.  This is done through the host file located in C:\Windows\System32\drivers\etc.  Open it up in Notepad with “Run as Administrator.”  An example entry is:   mywebsite.local   www.mywebsite.local

Step 3

Now it’s time to clone down my repo from Github.  This would be done inside C:\xampp\htdocs

Step 4

Next is to add entries in the C:\xampp\apache\conf\extra\ httpd-vhosts.conf file.  Add an example entry like:

<VirtualHost mywebsite.local>
DocumentRoot "C:\xampp\htdocs\myproj"

<VirtualHost www.mywebsite.local>
DocumentRoot "C:\xampp\htdocs\myproj"

Step 5

Install SQL Server drivers.  They can be downloaded at.  Once you download the drivers, extract them and install the one that matches the PHP version that you are using.  I am installing PHP 7.1 so I’ll be using the SQLSRV drivers 7.1.  Since this is a simple local Windows machine that doesn’t have multiple PHP threads running, I typically install the NTS (non-thread safe) drivers. The drivers goes into: C:\xampp\php\ext

Step 6

Add driver references to PHP and other configurations through PHP.ini which can be access through the XAMPP control panel.  A basic configuration I do is below, just make sure the SQLSRV dll(s) matches the filenames you placed in the ext folder in step 5:

date.timezone = America/Chicago ;override accordingly
short_open_tag: On ;override accordingly

Step 7

Download the SQL Server ODBC drivers from here and install them.

Step 8

Testing time.  I would create a simple test.php that has 

echo phpinfo();

and see if everything is installed correctly.  You should see that SQLSRV is mentioned on the page.  Start the webserver in XAMPP.  At this time, if you have IIS on, you need to turn it off for all sites.  This will prevent the two webservers from fighting over port 80.


Step 9 (Optional SSL Setup)

If you see your website by going to the url you have set (e.g. mywebsite.local), then you’re all set.  If you want to setup SSL, in httpd-ssl.conf which you can access from the Control Panel, look for this line:

<VirtualHost _default_:443>

and replace with

<VirtualHost _default_ *:443>

and make sure SSLEngine is on.  And make sure the DocumentRoot points to your project’s directory.  As for SSLCertificateFile  and SSLCertificateKeyFile you may have to specify the absolute path:

SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt"
SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key"