composer 永久忽略安装包时提示依赖 xx 扩展 作者: Chuwen 时间: 2024-07-02 分类: PHP ## 问题 在本地开发时,如果使用 composer 安装 composer 包经常会遇到这种提示: ``` Your requirements could not be resolved to an installable set of packages. Problem 1 - Root composer.json requires php ^8.3 but your php version (8.2.9) does not satisfy that requirement. Problem 2 - Root composer.json requires PHP extension ext-posix * but it is missing from your system. Install or enable PHP's posix extension. Problem 3 - Root composer.json requires PHP extension ext-rdkafka * but it is missing from your system. Install or enable PHP's rdkafka extension. Problem 4 - hhxsv5/laravel-s is locked to version v3.8.0 and an update of this package was not requested. - hhxsv5/laravel-s v3.8.0 requires ext-pcntl * -> it is missing from your system. Install or enable PHP's pcntl extension. Problem 5 - laravel/horizon is locked to version v5.24.4 and an update of this package was not requested. - laravel/horizon v5.24.4 requires ext-pcntl * -> it is missing from your system. Install or enable PHP's pcntl extension. Problem 6 - laravel/pail is locked to version v1.1.3 and an update of this package was not requested. - laravel/pail v1.1.3 requires ext-pcntl * -> it is missing from your system. Install or enable PHP's pcntl extension. To enable extensions, verify that they are enabled in your .ini files: - C:\Users\Shine\.pvm\versions\php-8.2\php.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-posix --ignore-platform-req=ext-rdkafka --ignore-platform-req=ext-pcntl` to temporarily ignore these required extensions. You can also try re-running composer require with an explicit version constraint, e.g. "composer require dcat/laravel-admin:*" to figure out if any version is installable, or "composer require dcat/laravel-admin:^2.1" if you know which you need. Installation failed, reverting ./composer.json and ./composer.lock to their original content. ``` ![](https://cdn.nowtime.cc/2024/07/02/2434538828.png) 实际上在本机开发过程中通常不需要用到这些依赖扩展,或者你是 Windows 作为开发环境,那么像 `posix`, `pcntl` 扩展在 Windows 上是安装不上的,所以我都会加上 `--ignore-platform-reqs` 选项,来跳过对这些扩展的检查,但是每次装 composer 包都要手打这个选项实在是太过繁琐,有没有直接替我加上这个选项的方法? ## 过程 通过查阅[Composer 官方文档](https://getcomposer.org/doc/03-cli.md#composer-ignore-platform-req-or-composer-ignore-platform-reqs "Composer 官方文档"),确实有这么一个方法,设置一个环境变量 `COMPOSER_IGNORE_PLATFORM_REQS=1` 即可解决 ## 结果 Windows 添加环境变量 1. 按下 `Win` + `R` 输入 `sysdm.cpl` 然后按 `Enter` 2. 选择“环境变量” 3. 新建环境变量 4. 输入变量名 `COMPOSER_IGNORE_PLATFORM_REQS` 5. 输入变量值 `1` 6. 确定 -> 确定 -> 确定 7. 完成 ![](https://cdn.nowtime.cc/2024/07/02/3423099981.png) 标签: Composer