安装 Composer 报错 PHP Warning: copy(): SSL operation failed with code 1. OpenSSL Error

报错内容
[root@localhost ~]# php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
PHP Warning:  copy(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in Command line code on line 1
 
Warning: copy(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in Command line code on line 1
PHP Warning:  copy(): Failed to enable crypto in Command line code on line 1
....省略
解决办法
  1. 先检查 openssl 是否安装
  2. 下载 cacert.pem
  3. 修改 php.ini 文件,引入 cacert.pem 证书
一. 检查是否安装openssl

执行:openssl version 命令 看是否返回 OpenSSL 1.0.2k-fips 26 Jan 2017 这种版本信息
或者查看 /usr/local/openssl 目录是否存在
安装openssl的流程, 已安装的跳过

1. 下载
wget --no-check-certificate https://www.openssl.org/source/old/1.1.1/openssl-1.1.1.tar.gz
2. 解压并切换目录
tar -zxvf openssl-1.1.1.tar.gz
cd openssl-1.1.1
3. 设定Openssl 安装,( --prefix )参数为欲安装之目录,也就是安装后的档案会出现在该目录下
./config --prefix=/usr/local/openssl
4. 执行命令
./config -t
5. 执行make、make install,编译Openssl
make & make install
二. 下载 cacert.pem
1. wget --no-check-certificate http://curl.haxx.se/ca/cacert.pem
// 把 cacert.pem移动到 /usr/local/openssl/certs/ 目录, certs这个目录默认不存在, 也可手动创建后, 把cacert.pem 上传上去
2. mv cacert.pem /usr/local/openssl/certs/cacert.pem
三. 修改php.ini

打开php.ini文件后, 搜索 openssl.cafile , 取消注释, 并填写cacert.pem路径

[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile=/usr/local/openssl/certs/cacert.pem

修改后保存, 然后重启 php-fpm

最后重新安装composer

执行
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"

如果提示报错 PHP Warning: failed loading cafile stream 检查下cacert.pem路径是否有问题

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值