Re: Some extensions can't be loaded by mod_php without adding PHPdirectory into PATH
[email protected] ("Christoph M. Becker") Thu, 4 Nov 2021 13:36:38 +0100
| Newsgroups | php.internals.win |
|---|---|
| Message-ID | <[email protected]> |
On 03.11.2021 at 15:57, Evgeny Vrublevsky wrote:
> There is a longstanding issue with mod_php for Apache when PHP extension=
s
> can't be loaded without adding PHP directory to PATH because they rely o=
n
> 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 th=
e
> others try to load their extensions from that directory in PATH, and fai=
l.
>
> 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 AddDllDirect=
ory
> function for it. It could be made in the DllMain of the php8apache2_4.dl=
l
> like this:
>
> #define WIN32_LEAN_AND_MEAN
> #include <windows.h>
> #include <shlwapi.h>
>
> DLL_DIRECTORY_COOKIE dircookie =3D nullptr;
> DWORD instances =3D 0;
>
> BOOL APIENTRY DllMain(HMODULE hmodule, DWORD dwreason, LPVOID lpreserved=
)
> {
> TCHAR path[MAX_PATH];
> path[0] =3D 0;
>
> switch (dwreason)
> {
> case DLL_PROCESS_ATTACH:
> if ((instances++) =3D=3D 0 && !dircookie)
> {
> SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
> GetModuleFileName(hmodule, path, MAX_PATH);
> PathRemoveFileSpec(path);
> dircookie =3D AddDllDirectory(path);
> }
> break;
>
> case DLL_PROCESS_DETACH:
> if ((--instances) =3D=3D 0 && dircookie)
> {
> RemoveDllDirectory(dircookie);
> dircookie =3D nullptr;
> }
> break;
> }
> return TRUE;
> }
>
> Could you please consider adding something like this to make PHP not rel=
y
> on PATH?
I have no strong feelings about this; setting the PATH as needed
shouldn't be an issue for a developer, but some convenience is nice as
well. I suggest that you submit a pull request[1], though.
Also note that we still support Windows 7/Server 2008 RC2, so this would
require some special handling (unless we want to drop support for these
Windows versions as of PHP 8.2).
[1] <https://github.com/php/php-src/pulls>
=2D-
Christoph M. Becker