Jump to content


Photo

Apache and PHP extensions problem


  • Please log in to reply
4 replies to this topic

#1 cliveb

cliveb
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 April 2017 - 07:59 AM

Hi - new member here with a seemingly bizarre problem with PHP extensions and Apache2 running under Windows 7 Pro.

Apache2 is working fine for simple PHP scripts. But when I want to use any extensions (MySQL in this case), Apache2 fails to load the DLL.

PHP from the command line works just fine using the extension.

In the Apache2 error log I see this on startup:

PHP Warning:  PHP Startup: Unable to load dynamic library './php_mysqli.dll' - The specified module could not be found.\r\n in Unknown on line 0

So I thought "Aha! Apache must be running in a different directory - easy fix"

I edited PHP.INI and changed extension_dir to C:/php/ext/; now I see this in the Apache2 log:

PHP Warning:  PHP Startup: Unable to load dynamic library 'c:/php/ext/php_mysqli.dll' - The specified module could not be found.\r\n in Unknown on line 0

So then I wondered if perhaps command line PHP was using a different PHP.INI. To test this, I deliberately edited the mysqli extension in PHP.INI with an invalid name, and PHP from the command line (as expected) said this:

PHP Warning:  PHP Startup: Unable to load dynamic library 'c:/php/ext/php_mysqli_xxx.dll' - The specified module could not be found.
 in Unknown on line 0


And the Apache2 error log says:

PHP Warning:  PHP Startup: Unable to load dynamic library 'c:/php/ext/php_mysqli_xxx.dll' - The specified module could not be found.\r\n in Unknown on line 0

Which proves that they are using the same PHP.INI.

 

I also tried using backslashes instead of forward slashes in PHP.INI just in case Windows wanted them, but got this:

 

PHP Warning:  PHP Startup: Unable to load dynamic library 'c:\\php\\ext\\php_mysqli.dll' - The specified module could not be found.\r\n in Unknown on line 0

 

The last thing that occured to me was perhaps permissions were wrong, as Apache2 runs under the SYSTEM account. But I checked and SYSTEM has full permissions to the DLL and all folders leading to it.

So I'm baffled. Can anyone suggest anything else to try?



#2 requinix

requinix
  • Administrators
  • Forgotten Administrator
  • 8,694 posts
  • LocationWA

Posted 18 April 2017 - 08:19 PM

The "module could not be found" error can also mean that a dependency of the DLL cannot be loaded. The only ones in php_mysqli.dll should be basic PHP stuff and other system files you already have - unless you're running an old PHP (at least <7.0) in which case you need to upgrade.

What PHP do you have and where did you download it?

#3 cliveb

cliveb
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 April 2017 - 07:51 AM

Thanks for the reply. I hadn't realised it could be other dependencies. I tried activating some other random extensions to check (such as dbase, mssql, bz2 and the like) and there were no errors about them in the Apache log.

 

I am running an old PHP (5.2.9), along with an old Apache (2.0.54). I just had the install files lying around from way back (when it had all worked fine on Windows XP).

 

I'll get the latest Apache2 and PHP and see what happens.



#4 requinix

requinix
  • Administrators
  • Forgotten Administrator
  • 8,694 posts
  • LocationWA

Posted 19 April 2017 - 08:22 AM

Holy crap, 5.2? Yeah. Upgrade. PHP 7.0 and Apache 2.2 at the earliest.

Anyway, mysql and mysqli back then used libmysql - the former was the PHP API as an optional DLL like normal, the latter was the actual driver itself and had its own DLL. Since libmysql.dll and php_mysqli.dll are in different places, and neither are generally visible to the Apache process (technically, visible to Windows when it searches for DLLs that are being loaded by Apache), that fails. The most common solution to this was to copy libmysql.dll into Windows\System32 where Windows would have no problem finding it, however that's actually a bad practice.

#5 cliveb

cliveb
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 20 April 2017 - 09:27 AM

I was aware of the libmysql.dll issue and had put a copy into Windows\system32, so that wasn't the issue.

 

Anyhow, I've upgraded to PHP 7.0 and Apache 2.4 and all is now working fine.

 

Many thanks for your help - much appreciated.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users