报错内容
[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
....省略
解决办法
- 先检查
openssl
是否安装 - 下载
cacert.pem
- 修改
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路径是否有问题