she swears <i>geek</i> is a term of endearment

PHP and MySQL on Windows IIS Error / Solution

I’ve set up PHP and mySQL no less than a dozen times over the last two years for various reasons.  Each time, I am astounded by how inconsistent the experience is.  Once it works, it works.  However, getting there can be a breeze or it can be a pain in the neck.  Documentation sucks and troubleshooting is impossible.  My hope is to save someone the hours I spent over the last couple of weeks trying to get WordPress and MediaWiki configured on a new Windows Server 2003 machine.

Order of Operations

First, make sure you have IIS installed and configured and that you can serve asp pages through IIS.  If you can’t do that, you’re going to have no luck with php.

Next, I recommend installing MySQL and then PHP.  No worries if you don’t follow that sequence but it helps you to ensure some details later.

When you install MySQL, make sure you can connect via some non php tool using your expected credentials.  I love MySQL Administrator available from the MySQL website.

Installing MySQL

MySQL is pretty straight forward.  Just run the latest installer, accept the defaults.  Done.  Keep in mind that MySQL will require some configuration to expose it outside the local machine, if that’s your infrastructure goal, but local execution is ready out of the box.  I usually create users for my PHP apps using MySQL Administrator.

Installing PHP

Do not use the installer.  From what I’ve read it tries to configure CGI and CGI is just silly.  Isapi is far superior but, as I experienced, has some hidden issues that are difficult to resolve.  More on that in a sec.  The bottom line, however, is that the installer has never worked for me, not once. 

Follow the instructions on the for a manual php install on Windows and enable (at least) mySql and MBString extensions (uncomment the lines referring to them in php.config).

Configure a website to serve php, using isapi, and ensure you can serve a php page.  Here’s the most useful thing you can do to prove php execution.

<?php
phpinfo ();
?>

 

Windows Path Environment Variables

I’m not a fan of throwing anything in System32 so I use the PHPRC environment variable to tell php where to load config from. 

More importantly, the PATH environment variable needs to know where php and its extensions are.  include both of these directories in the PATH.  Make sure PHP comes before MySQL in the list.

PHP / MySQL Access Violation

I experienced "PHP has encountered an Access Violation at 015B73DD" each time any MySQL operation was attempted.  There was no Windows event record, no logged issue, no information to the screen and nothing registered with SysInternals FileMon or RegMon.  This issue sucked about as hard as any computer frustration could.  I finally found a post about Installing PHP on IIS 6 where he referenced someone else’s observation: "Adam Carter worked through this problem …insightful conclusion …problem was caused by his mySQL install’s bin folder being included in the PATH before PHP’s install folder. …mySQL’s libmysql.dll loaded before PHP’s libmysql.dll file …upon loading its mySQL extension [causing access violation].  [fix: ensure php precedes mysql in the path] enabled PHP to find its own libmysql.dll"

The error: "PHP has encountered an Access Violation at xxxxxxx" changes the number but does not provide any other useful information and there is no information on the net regarding fixing this.  Well, now there is :)

Conclusion

I hope I saved someone from this hellishness.  There are quite a number of great php apps available and its a shame that its so hard to get through install issues.  Now that I am a Mac convert, I believe most of these issues are a result of the way Windows loads and operates rather than some deficiency in the php stack.  Its worth noting that php on windows is more of a port form apache than part of a design intent.  I am going to load up a Linux WMWare machine and see how that experience works for a Windows guy.  For now, I’ve got Windows working and I feel confident the install is reliable.  It just required a lot of screwing around to get there.   Cheers.

One Response to “PHP and MySQL on Windows IIS Error / Solution”

  1. THANK YOU for posting this. Another thing to mention is how IIS gets hooked up with PHP. There seem to be 2 ways:
    1) Right-click on your web site, go to the Home Directory tab, click Configuration near the bottom, go through the list and find .php and make sure the correct path to the DLL is there. For me the path is C:\PHP\php5isapi.dll
    2) Under Web Service Extensions, PHP appears there. For me I have things working with C:\PHP\php5isapi.dll listed there and nothing else (i.e. don’t have the CGI.exe listed there)

Leave a Reply