Installing PHP on Windows Server

I do a bit of web development at my job. One of the applications that I wrote is a PHP application that generally needs to be installed locally at client sites on a Windows server. Since a lot of people are moving to Server 2012, I had to start installing PHP on these servers, but I ran into quite a few snags along the way. The kicker to all of this is that I needed to get all of this installed without an internet connection.

One of our unique requirements is that the servers we install on usually do not have access to the internet, only an intranet, so we need to be able to do all of the install offline. Fortunately, Microsoft provides some tools to make this possible.

Web Platform Installer

One of the easiest ways to get PHP set up on Windows Server environments is Microsoft's Web Platform Installer. This program makes it easy to install and setup a large number of open source tools such as PHP, Wordpress, Python, and more. As of WPI v4, it has the option to create an offline cache from which to install on a computer without internet access. Below is a rough overview.

  1. Install WPI on a computer with internet access.
  2. Run the WPI command line utility to create an offline cache.
  3. WPI gets all of the dependencies of the selected package and caches them.
  4. Transfer the the cache to the desired computer.
  5. Run the install using the WPI command line utility and specify the cache as the source.

The first step is pretty self explanatory. You can get the latest version of WPI from Microsoft's web site. Once it is installed, open up a command prompt (with admin privileges).

cd C:\Program Files\Microsoft\Web Platform Installer
WebpiCmd-x64.exe /Offline /Products:PHP55 /Path:c:\offlinecache

Feel free to substitute the latest version of PHP for PHP55 and a path of your choosing for c:\offlinecache. This command will create the cache with the specified program and all of its dependencies at the location specified with /Path. From here, you just need to copy the offlinecache folder to the computer that you want to install PHP on. Once that is done, open a command prompt with admin privileges and navigate to the folder. Than run the following:

cd bin
WebpiCmd-x64.exe /Install /Products:PHP55 /XML:..\feeds\latest\webproductlist.xml

It will ask you if you have read and accept the EULA for all of the software products that you are installing, which, of course, you have, so answer yes to that prompt and then you are on your way.

.NET 3.5

If you try that on Server 2008, everything will work wonderfully. If you try that on Server 2012, you will get a message saying that you don't have .NET 3.5 installed. Oh good. We can just go to the server manager and install that feature... Except that when you go to do that, you will get a message saying that you need to specify alternate sources. Microsoft not only doesn't have it installed by default-- it is not even part of the OS install. In order to get .NET 3.5, you need to install it from the Server 2012 installation media. This frustratingly increases the size of our installation by quite a bit. We need to get those files to the new server and install .NET 3.5.

  1. Mount a server 2012 ISO or insert a server 2012 DVD.
  2. Navigate to \sources.
  3. Copy the sxs folder to your desired server.
  4. Install .NET 3.5 as a server feature specifying the sxs folder as an alternate source.

MS C++ Redistributable

Now that we have that taken care of, we can run the command to install PHP again and pull up our web application. Except... We get a 500 Error! Fast CGI crashes with the error code 0x??????. After spending some time looking around, it looks like this is because PHP has another dependency that we need to take care of. It is missing a DLL that comes with Microsoft C++ Redistributable 2010.

The End Result

Now that you have all of the dependencies installed, your PHP application should be running just fine. That took quite a bit more effort than it should have for a vendor provided tool. Hopefully they will update these tools soon with new builds that don't have these outdated dependencies. Until then, hopefully this guide helps someone out.