I had a bit of a frustrating time this week configuring my development computer at work. I’m a Windows guy. Not so much because of choice, but because that was the road well-traveled. But enough of that.
My company’s website runs on a Linux box hosted elsewhere. Since I’m the only developer here that is suitably proficient with web technologies, it’s my job to maintain and develop the company site. Pretty standard stuff: PHP scripts, mysql database, and Apache web server.
You may see where this is going. I’m developing on a Windows workstation, so my environment is obviously much different from the production environment. Not the best of situations, but hey, it’s only PHP and mysql, right?
So I got PHP and mysql all happy and square on my machine. Yay. But PHP is still running under IIS, and since my machine is running Windows 2000, it’s running an older version of IIS. Ultimately, I ran into a “feature” of IIS in which cookies simply cannot be sent when there is a redirect using the “Location” header. From what I can tell, IIS sees the Location header and sends it immediately to the client, completely ignoring any cookie data that was set beforehand. How rude.
After a day or two of cursing and scouring the internet for a solution, I came to the realization that there simply was no solution. So I decided to install Apache and bypass IIS.
After I got Apache and PHP all squared away (yay), I spent another frustrating day trying to figure out why PHP wasn’t loading its mysql module. It worked in IIS, but for some reason Apache didn’t want to let PHP play with mysql. After more cursing, I finally fell upon Apache’s error log, which reported something strange:
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\PHP\\apache\\ext\\php_mysql.dll' - The specified procedure could not be found.\r\n in Unknown on line 0
Something was not happy with php_mysql.dll. I immediately realized I must be in dll hell. A little more scouring of the internet unearthed this little gem of a blog post:
The php_mysql.dll module loads libmysql.dll, but apparently it has to be the version against which it was compiled. The required DLL is bundled with PHP, but what if an older, incompatible version of that DLL is found earlier in the search path? You’re hosed, that’s what if, and the module load fails with a message to the log file like so:
PHP Warning: PHP Startup: Unable to load dynamic library 'D:\\php-5.2.3\\ext\\php_mysql.dll' - The specified procedure could not be found.\r\n in Unknown line 0
Oh lordy, that’s my error too! I applied his solution and a few seconds later my PHP was happily talking to mysql. Thank you, Sander, for lifting my soul from dll hell to purgatory.
His comments are turned off, or I would have posted my gratitude there.
EDIT: I’m including his solution in case his blog gets eaten by the internet:
How do we solve this the Apache Way? Not by copying DLLs around, that’s for sure. The Apache configuration language has the LoadFile directive for this particular purpose. Loading the correct DLL right before the PHP module:
LoadFile “d:/php-5.2.3/libmysql.dll”
LoadModule php5_module “d:/php-5.2.3/php5apache2_2.dll”
makes PHP pick up the right symbols to run with MySQL.