Installing WordPress is a relatively simple task but I was recently asked to install a WordPress Blog with some unique requirements. The main requirement was that the Blog needed to be integrated into the main website structure and be accessed by a URL such as "http://website.com/blog".
After doing some reading this seemed perfectly OK except for the fact they wanted WordPress installing on it's native environment of Linux using MySQL. This instantly caused complexities so it was put forward that we run it on a Windows platform and use their existing SQL 2008 R2 database server to host the content.
This gave us some added benefits in that we did not need to worry about another backup and D.R solution for the new hardware hosting WordPress. After investigating installing WordPress using SQL Server it seemed perfectly simple but after looking around it seemed that lots of information was missing or scattered all over the place and things were not as simple as it first looked.
In light of this I was inspired to write this Blog post to share this information from one source rather than the headache of trying to hunt it all down. This post has been split into two sections.
Installing WordPress on Windows using SQL Server 2008 R2 Part 1 - This section will cover installing and configuring PHP and IIS 7.5.
Installing WordPress on Windows using SQL Server 2008 R2 Part 2 - This section will cover configuring your SQL Server and installing and configuring WordPress.
Setting up the Platform
As most people know you will need PHP installing in order to run WordPress. If you are installing this on a fresh Windows 2008 R2 server you will also need to make sure you have the Microsoft Visual C++ 2008 Redistributable Package (x86) installed before installing PHP. You will also need to make sure you have the IIS Web Server Role installed on your server. So the list of things to setup first are:
- Setup IIS Web Server Role on server. You can find more information at the following link on how to do this. http://www.iis.net/learn/install/installing-iis-7'%20and%2070-68='2/installing-iis-7-and-above-on-windows-server-2008-or-windows-server-2008-r2 When installing the ISS Web Server role you will be prompted that the .Net 3.5 Framework will also need to be installed as a dependency. It may also be worth installing the latest .Net Framework as well.
- The second thing to do would be to install the C++ Runtime Package. You can download and install this from here. You will need to install the x86 version of this.
- The third thing you will need to do is install the SQL Native client on your machine. You can download and install this from the following link http://go.microsoft.com/fwlink/?LinkID=188401&clcid=0x409
- The next thing to do will be to download and install the latest version of PHP for Windows. Instructions are below for this.
Firstly you will need to download the latest version of PHP for Windows. You can get this from the following links:
I downloaded the VC9 x86 Non Thread Safe (2013-Jan-16 21:42:34) installer. The difference between Non Thread Safe and Thread Safe is basically to increase performance along side the FastCGI protocol setup in IIS. To find out more on this subject please read the following link http://www.iis-aid.com/articles/my_word/difference_between_php_thread_safe_and_non_thread_safe_binaries
When installing accept the T&Cs and choose an install path.
It doesn't matter where but I used the default path. If you are planning to run multiple versions of PHP on the same server then it may be worth changing the path to incorporate a folder for the current version you are downloading and installing. Click Next
Select IIS FastCGI as the support protocol. FastCGI for IIS enables popular application frameworks that support the FastCGI protocol to be hosted on the IIS web server in a high-performance and reliable way. FastCGI provides a high-performance alternative to the Common Gateway Interface (CGI). CGI is a standard way of interfacing external applications with Web servers that has been supported as part of the IIS feature-set since the very first release. More information on this can be found here. Click Next.
Now you will have to select the PHP features you require.
I added all of the Script Executable and Extras features. The other features can be left as default. Click Next until the installation starts. Once finished we need to setup the SQL Server Drivers for PHP.
Installing SQL Server Support
This stage will allow you to setup all the support you need for SQL server and configure PHP for the WordPress install. The first thing you will need to do is download the correct SQL Driver for PHP. You can download the driver from the following link:
Download and save the SQLSRV20.EXE version to your machine in a directory of your choosing. Browse to the saved directory and run the EXE. You will be prompted with a security warning when running it so press to continue and the extraction will begin.
Agree to the licence Terms and Conditions.
Browse to a path to extract the Driver DLLs and click next.
Once you receive this message, click OK and browse to the directory you extracted the driver DLLs to. You should have the list shown below extracted to your directory.
The highlighted DLLs will be required based on whether you installed Thread Safe or Non Thread Safe versions of PHP. You will need to copy the highlighted DLLs to the ext directory of your PHP install folder. My path looked as follows C:Program Files (x86)PHPext. At this point you will need to update some PHP configs. But after doing some searching I found a tool that plugs straight into IIS 7.5 and allows you to configure PHP with ease. So at this point I recommend you download and install this plugin from the following link: http://phpmanager.codeplex.com/releases/view/69115
Download and install the correct version for your operating system. If you have IIS open, close it down and restart it. This will load the new plugin for PHP. Now we just need to setup the IIS website and register the driver for PHP.
Open IIS and browse to your sites folder. Right click and create yourself a new website. My site setup is shown below:
To create my test website I simply created a new Website through Visual Studio 2012 using one of the pre-packed templates. I then added a menu link to what will be my WordPress blog. So my link path looked like this "http://WordpressParent/Blog/". I then saved and built my project and copied it to my WordPress hosting machine and pointed my new website to it.
Next I needed to create myself a virtual directory to house my WordPress Blog inside my website. To do this right click on your new website and select "Add Virtual Directory". The properties of my directory looked like so:
Now we are done we just need to register the SQL Driver with PHP. We are going to do this by using the PHP manager through IIS. You can open this by clicking on your website and browsing to the PHP Manager under the IIS settings section.
Once you open the Manager for the first time it should detect your PHP installation automatically depending on where you have installed it. If it does not simply use the "Register new PHP version" link to browse the php-cgi.exe and register your installation. Also if this is the first time your registration has been accessed there will be a small warning about optimal configuration of PHP. Feel free to use the "View recommendations" link to sort this out and enable all the applicable recommendations.
Now we can register our drivers for SQL. To do this click on the "Enable or Disable an Extension" link to open the configuration window. You should now see the driver DLLs you copied to the PHP install directory in the Disabled section. Depending on the version of PHP you installed enable the correct driver. For example enable the drivers containing "_nts_" in the name if you installed the Non Thread Safe version of PHP. Now that we have completed this we have got SQL Server support enabled. But while we have the PHP Manager open we should do some other configurations before we finish.
Final Configurations of PHP and IIS
There are a couple of things that no-one ever covers in their posts about this subject and these things are what happens when you try to use your Blog. So these configs should help get rid of some of the problems you will face.
1.) Error Logging - If the user running your application pool in IIS does not have the correct permissions your error logging will fail. To sort this firstly we need to change the directory of the error logs. The default path is "C:Windowstempphp-errors.log". This will always cause problems with permissions so to resolve this lets change it to be hosted inside our website directory. This may not be suitable for some people using PHP but as we only want to use it to run WordPress this will be fine. To change the setting click the "Configure error reporting" link under the PHP Settings section.