首页 文章

无法找到包装器“https” - 您是否忘记在配置PHP时启用它?

提问于
浏览
126

问题在于问题 . 我已经对这方面的解决方案进行了彻底的调查,我知道有这方面的主题,我也跟着他们,没有任何工作 . 话虽这么说,我会列出到目前为止我所做的一切 . 我在Windows XP计算机上的最新Eclipse版本上使用Zend Debugging运行PHP 5.2.14 . 我有1 GB的RAM . 我安装了运行Apache,MySQL和FileZilla的XAMPP .

在XAMPP上我完成了以下操作(在这些更改期间Apache已关闭):从XAMPP控制面板单击Admin并转到 https:// localhost/xampp/ . 从那里我在欢迎页面上接受了这一行的证书:

对于OpenSSL支持,请使用https:// 127.0.0.1或https:// localhost的测试证书 .

在同一部分,我检查了 phpinfo() . 在'Environment'下, SERVER["HTTPS"]on . 在'Apache Environment'下, HTTPSOn . 在'PHP变量下, _SERVER["HTTPS"]On . 在'Phar'下, OpenSSL supportdisabled (安装ext / openssl) . 我不知道如何启用Phar one .

现在关于C:\ xampp中的文件本身,我去了PHP文件夹 . 在 生产环境 和开发php.ini文件下(比对不起更安全),我有 allow_url_fopen=Onallow_url_include=On ,并且我删除了分号,因此 extension=php_openssl.dll 不再被注释掉 . 我甚至确认.dll位于PHP文件夹的ext文件夹中 . libeay32.dll和ssleay32.dll都在PHP和Apache文件夹中 . Apache文件夹不包含 生产环境 或开发php.ini文件 .

为了安全起见,我去了http://www.slproweb.com/products/Win32OpenSSL.html并安装了Win32 OpenSSL v1.0.0d .

现在我的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);

我有两个其他网站,我查询,但他们通过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);

当我在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"
}

尽管我已经做了所有这些改变(在我启动Apache之后),但是当我第一次通过http://localhost/tutorial/retrieve_website.php访问Eclipse和Firefox中的PHP脚本时,我仍然会遇到相同的错误:

警告: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=removed API ID&cx =已移除的搜索ID&q = The Devil转到Georgia&alt = atom&num = 5)[function.file-get-contents]:无法打开流:第29行的C:\ xampp \ htdocs \ tutorial \ retrieve_website.php中没有这样的文件或目录警告:DOMDocument :: loadXML()[ domdocument.loadxml]:在第33行的C:\ xampp \ htdocs \ tutorial \ retrieve_website.php中作为输入提供的空字符串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”}

我忽略或未能做到的是什么?据我所知,我已经完成了有关HTTPS和OpenSSL的所有研究

19 回答

  • 31

    我通过在 /apache/bin/php.ini 中取消注释 ;extension=php_openssl.dll 在XAMPP中解决了它,尽管phpinfo()告诉我 /php/php.ini 是加载的ini文件 .

    EDIT: 我猜Ezra答案是直接将扩展行添加到相应的ini文件的最佳解决方案 .

  • 12

    我必须将 extension=php_openssl.dll 添加到位于 xampp/php/php.iniphp.ini 文件中 . 不知何故它不存在,在添加它并重新启动Apache之后一切正常 .

  • 2

    只需在php.ini文件中添加两行 .

    extension=php_openssl.dll
    allow_url_include = On
    

    它为我工作 .

  • 4

    您的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;
    }
    
  • 1

    我启用了openssl扩展,它对我有用:)

    ;extension=php_openssl.dll

    extension=php_openssl.dll

  • 1

    在我的情况下,问题是由于WAMP使用不同于php的php.ini而不是Apache,因此通过WAMP菜单进行的设置不适用于CLI . 只需修改CLI php.ini即可 .

  • 5

    在OpenSuse 12.1中,唯一需要的是:

    zypper in php5-openssl
    
  • 5

    对我来说,我必须这样做在php.ini中取消注释这些行:

    extension=php_openssl.dll
    extension_dir = "ext"
    

    如果php_openssl.dll位于“ext”文件夹中,则“ext”适用 .

    Note: 我必须为我的php.ini文件的 two 执行此操作,否则它将无法正常工作 . 一个位于vsphp安装文件夹中,另一个位于PHP文件夹中

    C:\Program Files (x86)\Jcx.Software\VS.Php\2013\Php 5.6
    C:\Program Files (x86)\PHP\v5.6
    

    Source

  • 18

    在MAC AMPPS上,我用以下内容更新了php-5.5.ini,现在它可以工作了 .

    allow_url_include = On
    extension=openssl.so
    
  • 91

    您可以改用此功能 .

    function get_url_contents($url){  
      if (function_exists('file_get_contents')) {  
        $result = @file_get_contents($url);  
      }  
      if ($result == '') {  
        $ch = curl_init();  
        $timeout = 30;  
        curl_setopt($ch, CURLOPT_URL, $url);  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  
        $result = curl_exec($ch);  
        curl_close($ch);  
      }  
    
      return $result;  
    }
    
  • 0

    请求https in Windows 的file_get_contents问题,取消注释php.ini文件中的以下行:

    extension=php_openssl.dll
    extension_dir = "ext"
    
  • 6

    在整天窥探之后,由于本指南,我想出了答案:http://piwigo.org/forum/viewtopic.php?id=15727

    基本上在Eclipse - > Windows - > Preferences - > PHP Executables下,有一节介绍了.exe和.ini的引用 . 当您从“帮助”菜单中的“日食安装新软件”安装PHP开发工具SDK功能时,默认目录位于Eclipse目录中 .

    因此,我添加了一个名为PHP 5.3.5(CGI)的新可执行文件,并从xampp的php文件夹中引用了cgi.exe和.ini .

    感谢webarto给你时间帮助我 .

  • 1

    我正在使用opsenSUSE Leap,我遇到了同样的问题 - 这意味着不支持OpenSSL . 这是我解决它的方式:

    • 打开YaST .

    • 转到软件管理 .

    • 在左窗格的搜索框中,输入'php5-openssl'并按返回键 .

    • 单击右窗格中'php5-openssl'旁边的复选框将其选中,然后单击'Accept'(这将添加OpenSSL支持) .

    • 重启Apache: sudo service apache2 restart

    就是这样,你已经完成了 .

  • 1

    我也得到了这个错误 . 我发现我的PHP版本没有编译openssl,所以简单地将扩展指令添加到php.ini是不够的 . 我不知道你在特定的情况下如何解决这个问题,但对我来说,我使用macports,命令只是:

    sudo port install php5-openssl
    
  • 2

    PHP7,在php.ini文件中,在 extension=openssl 之前删除";"

  • 5

    对于那些使用Winginx(基于nginx而不是基于Apache)的人,我用以下4个步骤修复它:

    • 在工具菜单上点击Winginx PHP5配置(不要介意名称中的 5 ):

    Winginx PHP5 Config

    • 选择您希望php.ini更改的PHP版本:

    PHP version selection

    • 在PHP Extensions选项卡上,选择 php_openssl 扩展名并点击Save按钮:

    php_openssl selection

    • 通过任务栏重启相应的PHP服务(停止并启动):

    Restart PHP service

  • -1

    试试这个:

    function curl($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);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        $buffer = curl_exec($curl);
        curl_close($curl);
        return $buffer;
    }
    
  • 167

    如果您正在使用wamp服务器,请转到图标单击此
    wamp server icon click on this

    然后转到PHP,然后点击PHP扩展,那将是php_openssl需要从那里激活并重启wamp服务器
    active php_openssl from here

  • 3

    在simple_html_dom.php中,将 $offset 变量的值从 -1 更改为 0 . 迁移到PHP 7时通常会发生此错误 .

    HtmlDomParser::file_get_html 使用 -1 的默认偏移量,传入 0 应解决您的问题 .

相关问题