2008-05-14

PHP fails to load MySQL Extensions claiming "The specified module could not be found" on Windows

I ran into this issue tonight after setting up Apache 2.2.8, PHP 5.2.6 and MySQL 5.1 on Windows XP SP3. I installed Apache using their installer and then manually configured httpd.conf. I downloaded the non-installer zip version of PHP; extracted it, saved a copy of php-ini-recommended as php.ini and manually configured it.

I correctly set the PHPIniDir setting in httpd.conf and set the correct extension_dir. I confirmed so by bringing up a page with phpinfo() called and it was showing my other extensions loaded. I'd comment one out (like php_gd2.dll) then restart Apache and refresh the phpinfo() page. The gd information disappeared, so I knew the settings were correct.

After a bunch of searching, I finally found a newsgroup post that pointed me in the right direction. there is another dll called libmysql.dll that comes with PHP (but is in the root PHP folder, NOT the ext folder.)

Both php_mysql.dll and php_mysqli.dll depend on this DLL. The fix was to copy this file to the WINDOWS directory. Once I did that, I restarted Apache and refreshed my phpinfo() page. There they were. Huzzah!

In my searching it seems people may run into this issue because of a few different things; so I'm publishing what I think is a good plan of attack for discovering what might be the problem when you can't get the MySQL extensions to load in PHP:

  • Confirm the extension_dir setting in php.ini is set correctly (trailing slash is required on Windows; I'm not sure about other operating systems. Example: C:/php/ext/)
  • Confirm the files exist in your extensions directory and are spelled correctly.
  • Ensure libmysql.dll is copied from the root PHP directory to the Windows directory. This is extremely important if you've upgraded PHP as well and have an older libmysql.dll in the Windows directory that may not work with the newer PHP code. Make sure the current PHP version's libmysql.dll is copied to the Windows directory.

If you have discovered anything I may have missed that would help others that also run into this issue; please leave your feedback here.

3 comments:

d_moyer said...

I am having this same issue, but with IIS and not apache. I have done and read everything on both the PHP and MySql websites for suggestions. I tried to copy this libmysql.dll to both the windows and the system32 folders, but still am getting the error that PHP can not load Mysql ext. Any ideas?

That One Guy said...

Have you done the phpinfo() test to see if other extensions are being loaded properly?

If they are, confirm your
extension=php_mysql.dll
line is uncommented.

I haven't tried running PHP under IIS yet but is it just calling out to the php.exe; or does it run as a module, requiring IIS be restarted each time php.ini is changed?

Let me know, and we'll move forward from there.

That One Guy said...

One friend of mine ended up having to copy to the Windows\System32 folder instead of the Windows folder to get it to work on his Vista install...

So if you can't get it to work by copying to the Windows folder, try the Windows\System32.

Best of luck!