Jump to content

Apache and PHP extensions problem


cliveb

Recommended Posts

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?

Link to comment
Share on other sites

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

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.