php在使用 composer 安装时报错集合
一、明明安装了扩展提示没有安装
/www/supper_admin # composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
Your lock file does not contain a compatible set of packages. Please run composer update.Problem 1- lcobucci/clock is locked to version 3.3.1 and an update of this package was not requested.- lcobucci/clock 3.3.1 requires php ~8.2.0 || ~8.3.0 || ~8.4.0 -> your php version (7.4.33) does not satisfy that requirement.Problem 2- maennchen/zipstream-php is locked to version 3.1.2 and an update of this package was not requested.- maennchen/zipstream-php 3.1.2 requires php-64bit ^8.2 -> your php-64bit version (7.4.33) does not satisfy that requirement.Problem 3- phpoffice/phpspreadsheet is locked to version 1.29.10 and an update of this package was not requested.- phpoffice/phpspreadsheet 1.29.10 requires ext-zip * -> it is missing from your system. Install or enable PHP's zip extension.Problem 4- psr/cache is locked to version 2.0.0 and an update of this package was not requested.- psr/cache 2.0.0 requires php >=8.0.0 -> your php version (7.4.33) does not satisfy that requirement.Problem 5- symfony/deprecation-contracts is locked to version v3.5.1 and an update of this package was not requested.- symfony/deprecation-contracts v3.5.1 requires php >=8.1 -> your php version (7.4.33) does not satisfy that requirement.Problem 6- symfony/event-dispatcher-contracts is locked to version v3.5.1 and an update of this package was not requested.- symfony/event-dispatcher-contracts v3.5.1 requires php >=8.1 -> your php version (7.4.33) does not satisfy that requirement.Problem 7- symfony/finder is locked to version v7.2.2 and an update of this package was not requested.- symfony/finder v7.2.2 requires php >=8.2 -> your php version (7.4.33) does not satisfy that requirement.Problem 8- symfony/service-contracts is locked to version v3.5.1 and an update of this package was not requested.- symfony/service-contracts v3.5.1 requires php >=8.1 -> your php version (7.4.33) does not satisfy that requirement.Problem 9- symfony/var-exporter is locked to version v6.4.21 and an update of this package was not requested.- symfony/var-exporter v6.4.21 requires php >=8.1 -> your php version (7.4.33) does not satisfy that requirement.Problem 10- nelexa/zip is locked to version 4.0.2 and an update of this package was not requested.- nelexa/zip 4.0.2 requires symfony/finder * -> satisfiable by symfony/finder[v7.2.2].- symfony/finder v7.2.2 requires php >=8.2 -> your php version (7.4.33) does not satisfy that requirement.To enable extensions, verify that they are enabled in your .ini files:- /usr/local/etc/php/php.ini- /usr/local/etc/php/conf.d/docker-php-ext-amqp.ini- /usr/local/etc/php/conf.d/docker-php-ext-bcmath.ini- /usr/local/etc/php/conf.d/docker-php-ext-gd.ini- /usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini- /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini- /usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini- /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini- /usr/local/etc/php/conf.d/docker-php-ext-redis.ini- /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-zip` to temporarily ignore these required extensions.
解决:
# 安装
composer install --ignore-platform-reqs# 添加组件
composer install <包名> --ignore-platform-reqs
–ignore-platform-reqs: ignore all platform requirements (php
, hhvm
, lib-*
and ext-*
) and force the installation even if the local machine does not fulfill these. See also the platform config option
忽略所有平台要求(php,hhvm,lib- *和ext- *)并强制安装,即使本地计算机不满足这些要求
二、多版本 PHP 下的 composer 使用
格式:
对应的php版本 composer的绝对路径 [操作]
以宝塔安装的 PHP7.4,php8.2为例子
php7.4环境下使用 composer
php74 /usr/bin/composer install
php8.2环境下使用 composer
php82 /usr/bin/composer install
三、composer 版本太低的更新
composer self-update
四、每次 composer 安装时提示 root 权限不安全
提示 “Continue as root/super user [yes]?”
vim ~/.bashrc# 把composer设置为全局
export COMPOSER_ALLOW_SUPERUSER=1