(已解决) 我现在已经卡了几天,试图有效地使用 composer 在为客户工作的 php 项目上安装 phpspreadsheet。由于 phpspreadsheet 需要 php >= 7.2,所以我在 Linux 驱动器 (ubuntu 20.04.2 LTS focal) 上安装了多个版本的 php (5.6、7.1、2、3、4、8.0)。我卸载了只有 php7.1 的 Ampps 服务器。Apache2 已经安装。我经过一些困难安装了 mysql-server 8.0(直到我清除了 ampps 安装)。
Composer 确实全局安装,并且我确实在 webroot 目录中初始化了一个基本的 composer.json。/vendor
创建了一个包含/composer
目录的目录。
我最近的 composer.json 文件:
{
"name": "john/t.cga.it8",
"description": "cga website",
"type": "project",
"license": "proprietary",
"authors": [
{
"name": "John Loughran",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require": {}
}
如果我$ composer diagnose
从终端的 Web 根目录运行,我会收到以下错误:
[Composer\Exception\NoSslException]
The openssl extension is required for SSL/TLS protection but is not available. If you can not enable the openssl extension, you can disable
this error, at your own risk, by setting the 'disable-tls' option to true.
尝试运行$ composer update
或upgrade
因相同错误而停止。
按照建议,当我将 Composer 配置为不使用 SSL 运行时,$ composer config -g -- disable-tls true
我获得了以下全彩色图像:
You are running Composer with SSL/TLS protection disabled.
Checking composer.json: OK
Checking platform settings: FAIL
The openssl extension is missing, which means that secure HTTPS transfers
are impossible.
If possible you should enable it or recompile php with --with-openssl
The zlib extension is not loaded, this can slow down Composer a lot.
If possible, enable it or recompile php with --with-zlib
A php.ini file does not exist. You will have to create one.
If you can not modify the ini file, you can also run `php -d option=value`
to modify ini values on the fly. You can use -d multiple times.
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: FAIL
[Composer\Downloader\TransportException] The "https://repo.packagist.org
/packages.json" file could not be downloaded: Unable to find the wrapper
"https" - did you forget to enable it when you configured PHP?
failed to open stream: No such file or directory
Composer is configured to disable SSL/TLS protection. This will leave
remote HTTPS requests vulnerable to Man-In-The-Middle attacks.
Checking github.com rate limit: FAIL
[Composer\Downloader\TransportException] The "https://api.github.com
/rate_limit" file could not be downloaded: Unable to find the wrapper
"https" - did you forget to enable it when you configured PHP?
failed to open stream: No such file or directory
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: <I removed the public keys here and below>
Dev Public Key Fingerprint:
OK
Checking composer version: Warning: Accessing getcomposer.org over http which is an insecure protocol.
OK
Composer version: 2.0.14
PHP version: 7.4.16
PHP binary path: /usr/local/bin/php
OpenSSL version: missing
cURL version: missing, using php streams fallback, which reduces performance
zip: extension not loaded, unzip present
针对错误中的一些观点进行解答:
Openssl 已使用 snap 安装到非标准位置。从浏览器来看,php 函数
loaded_extension('openssl')
返回 true。根据https://www.php.net/manual/en/imap.requirements.php我从找到 openssl 文件的地方创建了一个符号链接:$ ln -s /usr/bin/openssl /usr/local/ssl
并且类似地$ ln -s /usr/local/ssl/include /usr/include/openssl
。根据 Luke Welling 书中的建议,我安装了 JPEG、PNG、IMAP 和 zlib 库。
为了解决 php.ini“丢失”问题,我从终端获得:
john@john-desktop:~$ php7.4 -i | grep -i openssl
Warning: PHP Startup: Unable to load dynamic library 'openssl' (tried:
/usr/lib/php/20190902/openssl (/usr/lib/php/20190902/openssl: cannot open
shared object file: No such file or directory), /usr/lib/php/20190902
/openssl.so (/usr/lib/php/20190902/openssl.so: cannot open shared object
file: No such file or directory)) in Unknown on line 0
SSL Version => OpenSSL/1.1.1f
libSSH Version => libssh/0.9.3/openssl/zlib
openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.1.1f 31 Mar 2020
OpenSSL Header Version => OpenSSL 1.1.1f 31 Mar 2020
Openssl default config => /usr/lib/ssl/openssl.cnf
openssl.cafile => no value => no value
openssl.capath => no value => no value
Native OpenSSL support => enabled
也许我的符号链接有误?某些配置似乎有误,但我不知道如何修复它。
我确实有 php.ini 文件。对于 php7.4,phpinfo() 显示正在加载的主要文件(在浏览器中)位于 中/etc/php/7.4/fpm/
。我保留了它不变,但添加了一个phpcustomjl.ini
文件(优先级为 01),/etc/php/7.4/mods-enabled/
系统从 对其进行了符号链接/etc/php/7.4/fpm/conf.d/
。它显示在浏览器的 phpinfo() 中解析的附加 .ini 文件中。我学会了在对其进行更改后使用$ sudo systemctl restart php7.4-fpm
它,以便这些更改生效。.ini 文件中的相关行如下:
extension=zlib
;extension=/usr/lib/ssl
;extension=/usr/bin/openssl
extension=openssl
;extension=php_openssl
$ php7.4 --ini
表明此文件已在 cli 中加载。它输出:
Warning: PHP Startup: Unable to load dynamic library 'openssl' (tried: /usr/lib/php/20190902/openssl (/usr/lib/php/20190902/openssl: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/openssl.so (/usr/lib/php/20190902/openssl.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Warning: Module 'curl' already loaded in Unknown on line 0
Configuration File (php.ini) Path: /etc/php/7.4/cli
Loaded Configuration File: /etc/php/7.4/cli/php.ini
Scan for additional .ini files in: /etc/php/7.4/cli/conf.d
Additional .ini files parsed: /etc/php/7.4/cli/conf.d/01-phpcustomjl.ini,
这表明自定义 ini 文件正在从 cli 读取,所以其中的某些设置一定是有故障的?
$ php -v
当我在终端中运行时,我得到了PHP 7.4.16 (cli)
。在浏览器中,当我想启用 php7.4(目前是这样)时,我使用.htaccess
Web 根目录中的文件,并SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
在指令中使用。
我希望我有足够的细节让别人找出问题所在,或者提出任何策略。在那之前,我陷入困境!如果你能提供任何帮助,我将不胜感激。:-) 约翰
答案1
解决了:我安装了太多单独的 php 安装,以至于 Composer 不知道在哪一个中查找 openssl 或 php.ini。
下面的输出方式显示,从 CLI 来看,php 命令正在查找没有 php.ini 文件的目录(/usr/local/lib),而 php7.4 命令则在正确的位置查找。
我确实卸载并重新安装了 openssl 和 composer,并且当我尝试下面的命令时正准备启动 php。
现在我能够正确使用 Composer,并且我的项目目录中没有任何错误,只需输入
项目目录$ php7.4 /home/john/bin/composer update
代替
项目目录$ composer update
等等。一个大麻烦结束了!