I get an error: "Unable to find the wrapper https" when i execute file_get_contents via apache. I have already configured extension=openssl in php.ini. i try to dump the wrappers by using

echo var_dump(stream_get_wrappers());

and the result shows

screenshot from apache.

It seems that the https wrapper is indeed missing.

but file_get_contents works well under php interactive shell and stream_get_wrappers shows wrapper has been loaded as

screenshot from php interactive shell

what could be the reason for those different behaviours between apache and php shell? many thanks in advance for any hints

Environment: Apache 2.4.57 Win64 + PHP 8.2 (8.2.6) VS16 x64 Thread Safe


I solve this problem by installing another Apache version. the php.ini and httpd.conf are the same. thank you all in particular @hakre for friendly support

1

There are 1 best solutions below

5
hakre On

what could be the reason for those different behaviours between apache and php shell?

This can be answerwered straight forward: Both have a different PHP configuration.

Your PHP shell has the https wrapper enabled, your Apache PHP has it disabled.

This is often easy to overlook, especially when getting started, as we think this is all PHP so assume this must be the same.

But the truth is, that PHP has many different so called Server Application Programming Interfaces (SAPI), and they all come with their own configuration.

Compare with the PHP Manual: php_sapi_name()


In the shell, PHP is commonly of the Command Line Interface (CLI) SAPI.

In the webserver, like Apache, it depends, it can be Common Gateway Interface (CGI), an Apache Module or the Fast CGI (FCGI) process manager (FPM).

A potential gotcha

The defined SAPI may not be obvious, because for example instead of apache it may be defined as apache2handler. (ref)


Consequences

enlace then asked about two specific PHP SAPI configurations in comments:

  1. Where can I find the php configuration file for the shell?

For the shell, execute php -i, the output contains the location of the PHP ini file(s) at the beginning (pipe to more as it contains a lot of info).

  1. How can I configure the php.ini (for apache) correctly. I did enable extension=openssl but it doesnt work.

For the apache webserver, double check you edited the correct ini file, use phpinfo() to display ini locations and settings as default/effective.

Some SAPIs (like some in Apache) allow you to configure PHP settings within the Server configuration itself as well. Consult the part about configuration in the PHP manual for more details. The section is called Runtime Configuration.

Also identify the SAPI, so you have a better understanding what the runtime is and how you have configured it.