Composer常见错误解决

本文详细解析了在使用Composer进行依赖包安装时遇到的问题,包括版本冲突、PHP扩展缺失及内存不足等情况,并提供了具体的解决步骤,如忽略版本要求、安装扩展库及增加虚拟内存等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题说明:

执行composer install遇到错误:Your requirements could not be resolved to an installable set of packages. 这是因为不匹配composer.json要求的版本。

$ composer install

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel-notification-channels/webpush 3.0.0 requires minishlink/web-push ^2.0 -> satisfiable by minishlink/web-push[v2.0.0, v2.0.1].
    - laravel-notification-channels/webpush 3.0.1 requires minishlink/web-push ^2.0 -> satisfiable by minishlink/web-push[v2.0.0, v2.0.1].
    - minishlink/web-push v2.0.0 requires mdanter/ecc ^0.5.0 -> satisfiable by mdanter/ecc[v0.5.0, v0.5.1, v0.5.2].
    - minishlink/web-push v2.0.1 requires mdanter/ecc ^0.5.0 -> satisfiable by mdanter/ecc[v0.5.0, v0.5.1, v0.5.2].
    - mdanter/ecc v0.5.2 requires ext-gmp * -> the requested PHP extension gmp is missing from your system.
    - mdanter/ecc v0.5.1 requires ext-gmp * -> the requested PHP extension gmp is missing from your system.
    - mdanter/ecc v0.5.0 requires ext-gmp * -> the requested PHP extension gmp is missing from your system.
    - Installation request for laravel-notification-channels/webpush ^3.0 -> satisfiable by laravel-notification-channels/webpush[3.0.0, 3.0.1].

  To enable extensions, verify that they are enabled in your .ini files:
    - /usr/local/php7.2.9/etc/php.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.


提示我的PHP 7版本太高,不符合composer.json需要的版本,但是在PHP 7下应该也是可以运行的,composer可以设置忽略版本匹配,命令是:

$ composer install --ignore-platform-reqs 

或者

$ composer update --ignore-platform-reqs

 

问题二.

说明:报关于php gmp扩展问题

$ composer install 

Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - mdanter/ecc v0.5.2 requires ext-gmp * -> the requested PHP extension gmp is missing from your system.
    - mdanter/ecc v0.5.2 requires ext-gmp * -> the requested PHP extension gmp is missing from your system.
    - Installation request for mdanter/ecc v0.5.2 -> satisfiable by mdanter/ecc[v0.5.2].

  To enable extensions, verify that they are enabled in your .ini files:
    - /usr/local/php7.2.9/etc/php.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.


解决

说明:安装php gmp扩展库

$ yum install -y gmp-devel

$ cd /usr/local/php-fpm7.2.9/ext/gmp/

$ /usr/local/php-fpm7.2.9/bin/phpize

$ ./configure --with-php-config=/usr/local/php-fpm7.2.9/bin/php-config --with-gmp

$ make && make install



#在php.ini

加入:

extension=gmp.so


#重启php
/etc/ini.t/php-fpm restart

 

内存相关的报错

$ composer update nothing

Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 28 installs, 0 updates, 0 removals
  - Installing symfony/yaml (v3.4.23): The following exception is caused by a lack of memory or swap, or not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details

PHP Warning:  proc_open(): fork failed - Cannot allocate memory in phar:///usr/bin/composer/vendor/symfony/console/Application.php on line 952

Warning: proc_open(): fork failed - Cannot allocate memory in phar:///usr/bin/composer/vendor/symfony/console/Application.php on line 952
                                                     
  [ErrorException]                                   
  proc_open(): fork failed - Cannot allocate memory  
                                                   


解决:

增加虚拟内存,重新再执行composer install or composer update nothing 就不会报错啦

$ dd if=/dev/zero of=/tmp/newdisk bs=1024 count=1024000
$ du -sh /tmp/newdisk
$ mkswap /tmp/newdisk
$ chmod 0600 /tmp/newdisk
$ swapon /tmp/newdisk

 

转载于:https://my.oschina.net/AnnaWu/blog/3015134

在重新安装 Composer 过程中,可能会遇到以下常见错误: 1. "Could not open input file: composer.phar" - 这个错误通常是由于在命令中使用了错误的文件路径,或者没有在命令中指定正确的 Composer 文件名。确保你在命令中正确地指定了 Composer 文件的位置和名称。 2. "The following exception is caused by a lack of memory or swap, or not having swap configured" - 这个错误通常是由于你的服务器上没有足够的内存或交换空间来运行 Composer。你可以尝试增加服务器的内存或交换空间,或者在运行 Composer 命令时使用 --prefer-dist 标志来减少内存使用。 3. "Installation failed, reverting ./composer.json to its original content." - 这个错误通常是由于 Composer 在安装依赖项时遇到了错误。你可以查看 Composer 的输出信息来查找出错的原因,并尝试重新运行安装命令。 4. "Composer detected issues in your platform: Your Composer dependencies require a PHP version " - 这个错误通常是由于你的 PHP 版本不符合 Composer 依赖项的要求。你可以尝试升级 PHP 版本,或者在运行 Composer 命令时使用 --ignore-platform-reqs 标志来忽略版本要求。 5. "The requested PHP extension ext-xxx * is missing from your system." - 这个错误通常是由于你的系统缺少必需的 PHP 扩展,需要手动安装扩展或启用扩展。你可以通过搜索相关的扩展以及安装方法来解决问题。 希望这些信息对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值