无法找到包装器“https” - 您是否在配置 PHP 时忘记启用它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5444249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?
提问by John M
The problem is in the question. I've done a thorough investigation for solutions in regards to this and I know there are topics to this and I've followed them too and nothing has worked. That being said I'll list out exactly everything I've done so far. I am running PHP 5.2.14 with Zend Debugging on the latest Eclipse version on my Windows XP computer. I have a 1 GB of RAM. I have XAMPP running with Apache, MySQL, and FileZilla installed.
问题出在问题上。我已经对这方面的解决方案进行了彻底的调查,我知道有一些主题,我也遵循了它们,但没有任何效果。话虽如此,我将列出迄今为止我所做的一切。我在 Windows XP 计算机上的最新 Eclipse 版本上运行 PHP 5.2.14 和 Zend 调试。我有 1 GB 的 RAM。我在安装了 Apache、MySQL 和 FileZilla 的情况下运行了 XAMPP。
On XAMPP I've done the following (Apache was off during these changes):
Clicked on Adminfrom the XAMPP Control Panel and went to https:// localhost/xampp/
. From there I accepted the certs from this line on the welcome page:
在 XAMPP 上,我执行了以下操作(在这些更改期间 Apache 处于关闭状态):从 XAMPP 控制面板单击Admin并转到https:// localhost/xampp/
. 从那里我接受了欢迎页面上这一行的证书:
For OpenSSL support please use the test certificate with https:// 127.0.0.1 or https:// localhost.
对于 OpenSSL 支持,请使用带有 https:// 127.0.0.1 或 https:// localhost 的测试证书。
On that same section I checked phpinfo()
. Under 'Environment', SERVER["HTTPS"]
is on
. Under 'Apache Environment', HTTPS
is On
. Under 'PHP Variables, _SERVER["HTTPS"]
is On
. Under 'Phar', OpenSSL support
is disabled
(install ext/openssl). I don't know how to enable the Phar one.
在同一部分,我检查了phpinfo()
. 在“环境”下,SERVER["HTTPS"]
是on
。在“Apache 环境”下,HTTPS
是On
. 在“PHP 变量”下,_SERVER["HTTPS"]
是On
. 在“Phar”下,OpenSSL support
是disabled
(安装 ext/openssl)。我不知道如何启用 Phar one。
Now regarding the files themselves in C:\xampp, I went to the PHP folder. Under both production and development php.ini files (better safe than sorry), I have allow_url_fopen=On
, allow_url_include=On
, and I removed the semicolon, so that extension=php_openssl.dll
is no longer commented out. I even confirmed that the .dll is in the ext folder of the PHP folder. Both libeay32.dll and ssleay32.dll are in the PHP and Apache folders. The Apache folder doesn't contain either productive or development php.ini files.
现在关于 C:\xampp 中的文件本身,我转到了 PHP 文件夹。在生产和开发的php.ini文件(更好的安全比抱歉),我allow_url_fopen=On
,allow_url_include=On
和我删除了分号,所以extension=php_openssl.dll
不再注释掉。我什至确认 .dll 位于 PHP 文件夹的 ext 文件夹中。libeay32.dll 和 ssleay32.dll 都在 PHP 和 Apache 文件夹中。Apache 文件夹不包含生产或开发 php.ini 文件。
I've went to http://www.slproweb.com/products/Win32OpenSSL.htmland installed Win32 OpenSSL v1.0.0d for safe measure.
我已经去了http://www.slproweb.com/products/Win32OpenSSL.html并安装了 Win32 OpenSSL v1.0.0d 以确保安全。
Now the line of code in question in my retrieve_website.php looks like this:
现在,我的retrieve_website.php 中有问题的代码行如下所示:
$urlquery = "https://www.googleapis.com/customsearch/v1?key=".$appid."&cx=".$google_searchid."&q=".$query."&alt=atom&num=".$results;
$xmlresults = file_get_contents($urlquery);
I have two other websites that I query but they are served via HTTP and they work fine. I also have this line of code entered near the end of the script:
我还有另外两个网站可以查询,但它们是通过 HTTP 提供的,并且运行良好。我还在脚本末尾附近输入了这行代码:
echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_dump($w);
When I run it as a PHP Script on Eclipse, everything outputs perfectly fine the way I want along with these results:
当我在 Eclipse 上将它作为 PHP 脚本运行时,一切都以我想要的方式完美地输出,并带有以下结果:
openssl: yes
http wrapper: yes
https wrapper: yes
wrappers: array(10) {
[0]=>
string(5) "https"
[1]=>
string(4) "ftps"
[2]=>
string(3) "php"
[3]=>
string(4) "file"
[4]=>
string(4) "data"
[5]=>
string(4) "http"
[6]=>
string(3) "ftp"
[7]=>
string(13) "compress.zlib"
[8]=>
string(14) "compress.bzip2"
[9]=>
string(3) "zip"
}
Despite all these changes I've made (after I started up Apache), I still get the same errors the first time I access my PHP script in Eclipse and Firefox via http://localhost/tutorial/retrieve_website.php:
尽管我进行了所有这些更改(在我启动 Apache 之后),当我第一次通过http://localhost/tutorial/retrieve_website.php在 Eclipse 和 Firefox 中访问我的 PHP 脚本时,我仍然遇到相同的错误:
Warning: file_get_contents() [function.file-get-contents]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in C:\xampp\htdocs\tutorial\retrieve_website.php on line 29
Warning: file_get_contents(https:// www.googleapis.com/customsearch/v1?key=removed API ID&cx=removed search ID&q=The+Devil+went+down+to+Georgia&alt=atom&num=5) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\tutorial\retrieve_website.php on line 29
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input in C:\xampp\htdocs\tutorial\retrieve_website.php on line 33
openssl: no http wrapper: yes https wrapper: no wrappers: array(10) { [0]=> string(3) "php" [1]=> string(4) "file" [2]=> string(4) "glob" [3]=> string(4) "data" [4]=> string(4) "http" [5]=> string(3) "ftp" [6]=> string(3) "zip" [7]=> string(13) "compress.zlib" [8]=> string(14) "compress.bzip2" [9]=> string(4) "phar" }
警告:file_get_contents() [function.file-get-contents]:无法找到包装器“https”——您是否在配置 PHP 时忘记启用它?在 C:\xampp\htdocs\tutorial\retrieve_website.php 第 29 行
警告:file_get_contents(https://www.googleapis.com/customsearch/v1?key=已删除 API ID&cx=已删除搜索 ID&q=The+Devil+ go+down+to+Georgia&alt=atom&num=5) [function.file-get-contents]: 无法打开流:C:\xampp\htdocs\tutorial\retrieve_website.php 中第 29 行没有这样的文件或目录
警告: DOMDocument::loadXML() [domdocument.loadxml]:在 C:\xampp\htdocs\tutorial\retrieve_website.php 第 33 行中作为输入提供的空字符串
openssl:没有 http 包装器:是 https 包装器:没有包装器:array(10) { [0]=> string(3) "php" [1]=> string(4) "file" [2]=> string(4) ) "glob" [3]=> string(4) "data" [4]=> string(4) "http" [5]=> string(3) "ftp" [6]=> string(3) " zip" [7]=> string(13) "compress.zlib" [8]=> string(14) "compress.bzip2" [9]=> string(4) "phar" }
What is it that I have overlooked or failed to do? To my own knowledge, I've done everything that I've researched about concerning HTTPS and OpenSSL
我忽略了或未能做到的是什么?据我自己所知,我已经完成了有关 HTTPS 和 OpenSSL 的所有研究
回答by kjetilh
I solved it in XAMPP by uncommenting ;extension=php_openssl.dll
in /apache/bin/php.ini
despitephpinfo() telling me /php/php.ini
was the loaded ini file.
尽管phpinfo() 告诉我是加载的 ini 文件;extension=php_openssl.dll
,/apache/bin/php.ini
但我通过取消注释在 XAMPP 中解决了它/php/php.ini
。
EDIT:I guess Ezra answer is the best solution directly adding the extension line to the appropriate ini file.
编辑:我想 Ezra 的答案是直接将扩展行添加到适当的 ini 文件的最佳解决方案。
回答by Ezra
I had to add extension=php_openssl.dll
to my php.ini
file located in xampp/php/php.ini
. Somehow it was not there, after adding it and restarting Apache everything was working fine.
我不得不添加extension=php_openssl.dll
到php.ini
位于xampp/php/php.ini
. 不知何故它不在那里,在添加它并重新启动Apache之后一切正常。
回答by Roopchand
just add two lines in your php.ini file.
只需在 php.ini 文件中添加两行。
extension=php_openssl.dll
allow_url_include = On
its working for me.
它为我工作。
回答by Dejan Marjanovic
Your Apache is probably not compiled with SSL support. Use cURL instead of file_get_contents anyway. Try this code, if it fails then I am right.
您的 Apache 可能没有使用 SSL 支持进行编译。无论如何使用 cURL 而不是 file_get_contents 。试试这个代码,如果它失败了,那么我是对的。
function curl_get_contents($url)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
回答by Saran Pal
I have enable the openssl extention and it work for me :)
我已经启用了 openssl 扩展,它对我有用:)
;extension=php_openssl.dll
;扩展= php_openssl.dll
to
到
extension=php_openssl.dll
扩展=php_openssl.dll
回答by dtbarne
In my case, the issue was due to WAMP using a different php.ini for CLI than Apache, so your settings made through the WAMP menu don't apply to CLI. Just modify the CLI php.ini and it works.
就我而言,问题是由于 WAMP 对 CLI 使用的 php.ini 与 Apache 不同,因此您通过 WAMP 菜单进行的设置不适用于 CLI。只需修改 CLI php.ini 即可。
回答by TheSatinKnight
in OpenSuse 12.1 the only thing required was:
在 OpenSuse 12.1 中,唯一需要的是:
zypper in php5-openssl
回答by zeta
For me I had to uncomment these lines in php.ini:
对我来说,我必须在 php.ini 中取消注释这些行:
extension=php_openssl.dll
extension_dir = "ext"
"ext" is applicable if php_openssl.dll is located in the "ext" folder.
如果 php_openssl.dll 位于“ext”文件夹中,则“ext”适用。
Note:I had to do this for twoof my php.ini files otherwise it would not work. One located in the vs.php installation folder, and the other on on the PHP folder
注意:我必须对我的两个php.ini 文件执行此操作,否则将无法正常工作。一个位于 vs.php 安装文件夹中,另一个位于 PHP 文件夹中
C:\Program Files (x86)\Jcx.Software\VS.Php13\Php 5.6
C:\Program Files (x86)\PHP\v5.6
回答by Elye
On MAC AMPPS, I updated the php-5.5.ini with the following and now it works.
在 MAC AMPPS 上,我使用以下内容更新了 php-5.5.ini,现在它可以工作了。
allow_url_include = On
extension=openssl.so
回答by Shusen Yi
PHP7, in php.ini file, remove the ";" before extension=openssl
PHP7,在php.ini文件中,去掉“;” 前extension=openssl