通过Homebrew在macOS High SIerra上安装GMP

0 php gmp composer-php

我一直试图在我的机器上运行:https://github.com/Minishlink/web-push-php-example

创建项目并更改到composer install返回的目录后:

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.
Run Code Online (Sandbox Code Playgroud)

它列出的问题看起来都接近这个:

the requested PHP extension gmp is missing from your system.
Run Code Online (Sandbox Code Playgroud)

所以我通过Homebrew安装了gmp.

之后搜索gmp返回了这个:

==> Searching local taps...
gmp ?
==> Searching taps on GitHub...
==> Searching blacklisted, migrated and deleted formulae...
Run Code Online (Sandbox Code Playgroud)

但是,如果我检查列表,它返回的php -m是不存在的.

我也尝试将扩展名添加extension=gmp.so到php.ini,这导致了新的错误.

PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20160303/php_gmp.so'
Run Code Online (Sandbox Code Playgroud)

当然,composer install在我的项目目录中尝试时仍会遇到相同的错误.

请帮帮我!我不知道该怎么办...

小智 6

这些步骤帮助我解决了这个问题.安装php版本

brew install php@7.1
Run Code Online (Sandbox Code Playgroud)

添加〜/ .bash_profile或〜/ .zshrc的php路径:

export PATH="/usr/local/opt/php@7.1/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)

然后源文件,启动php并检查gmp是否已加载

brew services start php@7.1
source ~/.zshrc
php -info | grep "GMP"
Run Code Online (Sandbox Code Playgroud)

再试一次

composer install
Run Code Online (Sandbox Code Playgroud)