前言

起因是因我要安装

web3p/ethereum-tx

执行

composer require web3p/ethereum-tx

报错内容如下

# root @ www.axinblog.com in /home/wwwroot/axinblog on git:develop x [19:08:55]
$ composer require web3p/ethereum-tx
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Using version ^0.4.3 for web3p/ethereum-tx
./composer.json has been updated
Running composer update web3p/ethereum-tx
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- simplito/elliptic-php[1.0.6, ..., 1.0.9] require ext-gmp * -> it is missing from your system. Install or enable PHP's gmp extension.
- web3p/ethereum-tx 0.4.3 requires simplito/elliptic-php ~1.0.6 -> satisfiable by simplito/elliptic-php[1.0.6, 1.0.7, 1.0.8, 1.0.9].
- Root composer.json requires web3p/ethereum-tx ^0.4.3 -> satisfiable by web3p/ethereum-tx[0.4.3].

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

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

环境说明

  • Ubuntu 18.04.6 LTS
  • LNMP 1.8
  • PHP 7.3.28 & PHP 8.0.8 均测试通过

步骤说明

安装 GMP 开发库

sudo apt-get install libgmp-dev

安装 PHP GMP 扩展

安装
$ cd ~/lnmp1.8/src
$ tar jxvf php-7.3.28.tar.bz2
$ cd php-7.3.28/ext/gmp
$ /usr/local/php/bin/phpize
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make && make install

这里没装GMP 开发库

会报错

configure: error: Unable to locate gmp.h

启用扩展

/usr/local/php/etc/php.ini

;extension=gmp

extension=gmp

重启LNMP

lnmp reload

查看是否启用成功

$ php -m | grep gmp
gmp

问题解决

sc0vu/web3.php 0.1.4 requires php ^7.1 -> your php version (8.0.8) does not satisfy that requirement.

解决

composer install --ignore-platform-reqs

or

"require": {
"php": ">=7.3",
.....
},


"require": {
"php": "^7.3|^8.0",
.....
},

参考文献

PHP 手册 函数参考 数学扩展 GMP