Solution : Unable to load dynamic library C:\php\ext\php_mysql.dll - the specified module could not be found


  • OS : Windows XP
  • PHP Version : 5.0.4
  • Apache Version : Apache 2
  • MySQL Version : MySQL 4.1
  • PHP Installed at C:\php


On a new installation of PHP, after having installed Apache and MySQL when I enable the php_mysql.dll module in the php.ini file, upon restarting Apache I get the error message “Unable to load dynamic library C:\php\ext\php_mysql.dll - the specified module could not be found.” twice. Initially I was getting the error “Unable to load dynamic library .\php_mysql.dll - the specified module could not be found.” I am able to load other modules, just not php_mysql.dll.


The confusing thing about this error message is that “the specified module” that could not be found, is not php_mysql.dll as one would think. I’ll see the error message that it can’t find the module C:\php\ext\php_mysql.dll and then go to that directory and find myself looking at that exact file. The module that isn’t being found is a dll called libmysql.dll. This library is located in a couple places, C:\php\libmysql.dll and C:\Program Files\MySQL\MySQL Server 4.1\bin\libmySQL.dll. The one thing I did that fixed this problem was to copy libmysql.dll from C:\php to C:\Windows\System32. I’ve confirmed that the instance of libmysql.dll that php is looking for is “C:\php\libmysql.dll”. This effectively moves the libmysql.dll into the path (in that c:\windows\system32\ is always in the path). You can also modify your global environement path, and then restart your computer.

Solution User Comments

The C:\php\libmysql.dll is the one that should be used. It is all a matter of setting the “Path” environment variable to also point to C:\php. It should work from there. This is documented in the manual - it’s just not easy to spot. Comment by Rayne

After setting the Path-Environment Variable you should restart your system! Comment by sofastar

Rather than copy libmysql.dll to Windows\System32, copying it to Apache’s root folder (typically Program Files\Apache Group\Apache2) should also work. This may be preferable to burying in it System32 with a zillion other dlls Comment by anonymous

It seems that the php_mbstring.dll is mandantory for loading php_mysql.dll (beside the mentioning for php_exif.dll below). I just wanted to point that out, because it nearly drove me crazy. ;-) Comment by Borgond

PHP 5.0.xx also looks at the php.ini file for extensions’ paths. While it is true that many errors are the result of failing to find libmysql.dll, it might be that the error is telling the truth! Comment by anonymous


Assuming a standard installation, the following will be true:

  1. PHP is installed in c:\php.
  2. PHP.ini is located in c:\windows
  3. c:\php is not in the path variable.
  4. extension dlls are in c:\php\ext

Steps to make php work:

  1. Add c:\php to the system path. (control panel->system->advanced->env variables->path)
  2. REBOOT!
  3. open php.ini and uncomment the appropriate extension lines
    (i.e. extension=php_mysql.dll)
  4. modify php.ini to look for extensions in the path directory
    (i.e. extension_dir = "C:\php\ext\")
  5. restart the webserver.

It has been my experience that most users forget step 4. The only way that they get the dlls to work is to copy them to the system32 directory, which is a really bad practice.


The main difficulty in troubleshooting this issue is two-fold. One, the issue crops up in the default installation of PHP. This means that anyone who installs Apache PHP and MySQL on a Windows system, will have to manually copy this dll file to get it to work. This is absurd considering that the PHP Apache MySQL combination is about as vanilla as you get. Two, the error message that is displayed is an outright lie. This error message, “Unable to load dynamic library ./php_whatever.dll - the specified module could not be found.” is displayed when any php extension can’t be loaded. Another example is when you attempt to enable the php extension php_exif.dll. The exact same error message pops up, when the actual cause of the failure is that php_mbstring.dll must be loaded in the php.ini file prior to php_exif.dll. Again, the default behaviour up to PHP 5.0.4 is for the extensions to be listed alphabetically in the php.ini instead of by dependency.

So in summary, if you see the error “Unable to load dynamic library ./php_whatever.dll - the specified module could not be found.” ignore it, consider it to read “Unable to load dynamic library ./php_whatever.dll - something prevented PHP from loading the dynamic library but I can’t tell you what.”

What next

I think there are three initiatives that need to be implemented by the PHP developers in order to make PHP usable by non techies.

  • Make the default installation of PHP on any platform work right out of the box. The idea that dll files must be manually copied into the C:\Windows\System32 folder is asinine. The idea that one would have to go into the php-dict.ini or php-recommened.ini and re-order the extensions so they load in the order that the dependencies require is absurd.
  • Provide meaningful information in error messages and if there is no meaningful information, don’t provide false information. I believe that it would be easy to change an error message that says “Unable to load dynamic library ./php_mysql.dll - the specified module could not be found.” to “Unable to load dynamic library ./php_mysql.dll - the libmysql.dll module could not be found.” At least don’t show any error message if the contents are not true. “Unable to load dynamic library ./php_exif.dll - the specified module could not be found.” should be changed to something like “Unable to load dynamic library .\php_exif.dll - the specified module requires that php_mbstring.dll be loaded.”
  • Re-write the installation documentation from scratch. The online installation instructions (the instructions one must follow to install PHP, especially on Windows) were developed progressively, creating a veritable Choose-Your-Own-Adventure install process. There is no deliniation between what text in the page is a step in the process that must be completed and what is informational. There are many many different pages which all must be read to catch all of the steps, of which no clear order is provided to implement them.

Other Gotchas

  1. If your troubleshooting PHP under windows, and making modifications to the php.ini file and getting nowhere, make sure that the php.ini that you’re modifying is actually getting loaded. Create a test php file that displays phpinfo() and check the “Configuration File (php.ini) Path” value. Make sure it’s pointed to the file you’re modifying. The reason being, if the php can’t find a php.ini where it expects to find it, it doesn’t complain. It just uses all the defaults. I had to move php.ini into C:\WINDOWS. I believe one could also set the path to include whatever directory php.ini is in and it would work. You would however have to reboot the computer to get it to take the new path.
  2. If you’re setting the path in Windows to either get php to find php.ini or get some extension to find it’s related dlls, remember you have to reboot the whole computer after setting the path for it to become real.
  3. php_curl.dll requires libeay32.dll, and ssleay32.dll be available. This means somewhere in the path. If you haven’t modified the path, you’re going to need to copy these files to c:\Windows\System32

Some user feedback and thanks that people have submitted

Hi I’ve the same problem though it sudden;y appeared after upgrading mySQL and PHP for the whole trinity had been running smoothly before. If you copy the libmysql.dll into the apache bin directory this also kills the message and is probably a cleaner solution Hugh


Thank you so very much for posting this solution. I was struggling with the same problem when trying to load php_mysql.dll. I even had the php directory in my path and it didn’t work. Once I copied libmysql.dll from the php directory to \windows\system32 everything worked fine.


After messing with extension_dir in the php.ini file for an hour trying to figure out why it couldn’t see what was clearly there, I ran across your solution. I can’t believe it was that simple. This should be included in PHP’s documentation somewhere!

Thanks!!! Merci!!! =


Just spent an hour trying to get to the root of this problem, found your page and now it’s fixed - I agree with all your comments re PHP install documentation etc. Many thanks.

And Other spanish Thanks

I was searching lots of pages and nothing, thanks for this fast and nice way to fix this disturbing problems..



I cant believe this information isnt posted in more places!