php获取远程https内容时提示PHP Warning: copy(): Unable to find the wrapper “https“ 解决方法

PHP教程 2025-08-01

目录

  • 异常信息:
  • 异常原因
  • 解决方法: 安装 openssl扩展
  • 通过port search查找可用的php openssl扩展包参考

异常信息:

php -r copy(https://*get*compo*ser.org/installer, composer-setup.php);

PHP Warning: copy(): Unable to find the wrapper https - did you forget to enable it when you configured PHP? in Command line code on line 1

PHP Stack trace:

PHP 1. {main}() Command line code:0

PHP 2. copy($source_file = https://*get*compo*ser.org/installer, $destination_file = composer-setup.php) Command line code:1

Warning: copy(): Unable to find the wrapper https - did you forget to enable it when you configured PHP? in Command line code on line 1

Call Stack:

0.0001 388024 1. {main}() Command line code:0

0.0008 388024 2. copy($source_file = https://*get*compo*ser.org/installer, $destination_file = composer-setup.php) Command line code:1

异常原因

这个异常是因为当前的php没有配置openssl模块, 所以在php访问https的内容时就提示Unable to find the wrapper https异常。

解决方法: 安装 openssl扩展

在macos中通过macport安装php后,默认是没有安装openssl扩展的, 需要我们手动安装一下这个openssl的扩展。

# 首先确定当前php版本
php -version
 
# 然后安装 openssl扩展 , 这里以php7.2版本为例
sudo port install php72-openssl

如果你的php非port安装的,解决方法也是一样的,安装对应php的 openssl 扩展即可。

通过port search查找可用的php openssl扩展包参考

命令: port search --name --line --regex ^php(d+)-openssl