Some extensions can't be loaded by mod_php without adding PHP directory into PATH
[email protected] (Evgeny Vrublevsky) Wed, 3 Nov 2021 17:57:54 +0300
| Newsgroups | php.internals.win |
|---|---|
| Message-ID | <CAM9wj5H4XSrgBtcX6Z7NaJZA1xzUWzut_9JQ0MkDG4zMHyvBTw@mail.gmail.com> |
--0000000000001e474805cfe3a3e3
Content-Type: text/plain; charset="UTF-8"
Hi,
There is a longstanding issue with mod_php for Apache when PHP extensions
can't be loaded without adding PHP directory to PATH because they rely on
some libraries which are in the root PHP directory, and the OS looks for
them in the root Apache directory by default.
Also, it causes an issue when a user has a few versions of PHP installed
(with separate copies of Apache), one of them is in the PATH, and all the
others try to load their extensions from that directory in PATH, and fail.
It is possible to resolve this issue by adding the directory of php_mod dll
into the system list of dll directories. You should use the AddDllDirectory
function for it. It could be made in the DllMain of the php8apache2_4.dll
like this:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlwapi.h>
DLL_DIRECTORY_COOKIE dircookie = nullptr;
DWORD instances = 0;
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD dwreason, LPVOID lpreserved)
{
TCHAR path[MAX_PATH];
path[0] = 0;
switch (dwreason)
{
case DLL_PROCESS_ATTACH:
if ((instances++) == 0 && !dircookie)
{
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
GetModuleFileName(hmodule, path, MAX_PATH);
PathRemoveFileSpec(path);
dircookie = AddDllDirectory(path);
}
break;
case DLL_PROCESS_DETACH:
if ((--instances) == 0 && dircookie)
{
RemoveDllDirectory(dircookie);
dircookie = nullptr;
}
break;
}
return TRUE;
}
Could you please consider adding something like this to make PHP not rely
on PATH?
--
Best regards, Evgeny
--0000000000001e474805cfe3a3e3--