linux 安装 composer 时 SSL operation failed 的错误「附安装过程」

完整报错:

[root@VM_6_184_centos composer]# 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
PHP Warning:  copy(): Failed to enable crypto in Command line code on line 1
PHP Warning:  copy(https://install.phpcomposer.com/installer): failed to open stream: operation failed in Command line code on line 1

先到 curl 官网 curl.se/docs/caextract.html 下载证书
点击醒目的 cacert.pem 链接下载,得到 cacert.pem,上传至服务器。

编辑 php.ini (php --ini 查看 php.ini 真实路径),修改

openssl.cafile=/usr/local/openssl/ssl/certs/cacert.pem

重启 service php-fpm restart

再按照 composer 官方安装文档安装就可以了


附 composer 安装过程 (*全局安装):
pkg.xyz/#how-to-install-composer

[root@VM_6_184_centos certs]# cd /usr/local/composer/
[root@VM_6_184_centos composer]# ll
total 0
[root@VM_6_184_centos composer]# php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
[root@VM_6_184_centos composer]# ll
total 64
-rw-r--r-- 1 root root 58148 Nov 17 18:29 composer-setup.php
[root@VM_6_184_centos composer]# php composer-setup.php
All settings correct for using Composer
Downloading...

Composer (version 2.2.18) successfully installed to: /usr/local/composer/composer.phar
Use it: php composer.phar

[root@VM_6_184_centos composer]# ls
composer.phar  composer-setup.php
[root@VM_6_184_centos composer]# php -r "unlink('composer-setup.php');"
[root@VM_6_184_centos composer]# ls
composer.phar
[root@VM_6_184_centos composer]# mv composer.phar /usr/local/bin/composer
[root@VM_6_184_centos composer]# composer --version
Composer version 2.2.18 2022-08-20 11:33:38
[root@VM_6_184_centos composer]# composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.2.18 2022-08-20 11:33:38
php
本作品采用《CC 协议》,转载必须注明作者和本文链接
welcome come back
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
76
粉丝
20
喜欢
123
收藏
299
排名:373
访问:2.4 万
私信
所有博文
社区赞助商