如何在 macOS High Sierra 上安装 PHP GMP?

aks*_*ar6 7 php homebrew composer-php macos-high-sierra

我正在尝试为 PHP 安装和启用 GMP 扩展。

Mac OS High Sierra 10.13.5
PHP Version: 7.1.16
Composer version: 1.6.5
Homebrew version: 1.6.9
Run Code Online (Sandbox Code Playgroud)

运行时出现此错误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.

  Problem 1
    - The requested PHP extension ext-gmp * is missing from your system. Install or enable PHP's gmp extension.
Run Code Online (Sandbox Code Playgroud)

composer.json具有的依赖"ext-gmp": "*"。我尝试过以下事情:

  1. brew install homebrew/php/php70-gmp
  2. brew install gmp
  3. brew install homebrew/homebrew-core/php70-gmp
  4. 更改php.ini为启用extension=php_gmp.dll

我在 Composer 安装时仍然遇到同样的错误。任何人都可以帮我解决这个问题吗?

小智 3

重新开始。安装 PHP 7

brew install php@7.1

添加 php 路径到~/.bash_profile~/.zshrc:

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)

再试一次