无法在 macOS Sierra 上使用 Homebrew 安装 PHP 7

Unable to install PHP 7 with Homebrew on macOS Sierra

我正在尝试设置 Laravel 的 Valet,作为依赖项,它需要 PHP 7。当我尝试使用 Homebrew 安装 PHP 7 时,我得到以下信息错误:

Configuring SAPI modules
checking for Apache 2.0 handler-module support via DSO through APXS... 

Sorry, I cannot run apxs.  Possible reasons follow:

1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)

The output of /usr/sbin/apxs follows:
apxs:Error: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/apr-1-config not found!.

configure: error: Aborting

READ THIS: https://git.io/brew-troubleshooting
If reporting this issue please do so at (not Homebrew/brew):
  https://github.com/Homebrew/homebrew-php/issues

These open issues may also help:
php70-dbase  https://github.com/Homebrew/homebrew-php/issues/3508
php70-intl not found https://github.com/Homebrew/homebrew-php/issues/3591
php70-opcache install issue https://github.com/Homebrew/homebrew-php/issues/3586
Problem installing php70-mcrypt, php70-opcache, php70-xdebug on El Capitan https://github.com/Homebrew/homebrew-php/issues/3587
Add php70-zmq formula https://github.com/Homebrew/homebrew-php/pull/3474
Problem installing homebrew/php/php70-imagick https://github.com/Homebrew/homebrew-php/issues/3571
Install PHP70: Incompatible library version https://github.com/Homebrew/homebrew-php/issues/3444
brew install php70-redis https://github.com/Homebrew/homebrew-php/issues/2762
Allow --enable-redis-igbinary for php70-redis https://github.com/Homebrew/homebrew-php/pull/3473
Add head formula for php70-uploadprogress https://github.com/Homebrew/homebrew-php/pull/3178

这是全新安装的 MacOS Sierra(实际版本,不是 测试版)和全新安装的 Homebrew(已更新)。我已经安装,运行 并同意 Xcode 许可协议。

我不知道这些错误是什么意思。我该如何修复它们?

是的,我已经弄明白了。我在下面发布了成功安装所需组件的步骤,以防其他人偶然发现此问题:

1).确保 Homebrew 是最新的:

brew update

2).通过确保安装 Xcode 然后在终端中键入以下内容来修复 PHP 7 错误:

brew install apr apr-util
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/opt/apr/bin/apr-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/opt/apr-util/bin/apu-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/

3). 运行以下命令(否则PHP安装会报错缺少libz):

xcode-select --install

4).您现在可以使用 Homebrew 安装 PHP 7:

brew install homebrew/php/php70

我使用了以下命令使其工作。

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew update && brew install apr apr-util
brew link apr-util --force
brew link apr --force
which apu-1-config
which apr-1-config
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/bin/apu-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/bin/apr-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
brew install php70

对于那些通过 Homebrew 使用 macOS 交付的 Apache 安装和 PHP 的人来说,这可能也很重要(引自 Homebrew php70 安装):

随着 macOS Sierra 的发布,现在默认不构建 Apache 模块。如果你想在你的系统上构建它,你必须使用 --with-apache 选项安装 php。有关详细信息,请参阅 brew 选项 php70。

以下是我如何将我的 Macbook Pro (macOS Sierra) PHP 5.6 升级到 7.2

一个。先更新brew包。

$ brew update && brew upgrade

b。取消链接旧版本 PHP 如果它是用 Homebrew 安装的。

$ brew unlink php56

c。安装新版本 PHP.

$ brew install php72

安装后显示: 要在 Apache 中启用 PHP,请将以下内容添加到 httpd.conf (/etc/apache2) 并重新启动 Apache:

d。使用 vim 编辑 apache2 的 httpd.conf。

$ sudo vim /etc/apache2/httpd.conf

搜索“php5_module”然后表扬如下语句:

#Comment out the PHP5 module
#LoadModule php5_module libexec/apache2/libphp5.so

添加命令如下:

#Enable PHP 7 module
LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so

<FilesMatch \.php$>
  SetHandler application/x-httpd-php
</FilesMatch>

e。最后,检查 DirectoryIndex 包括 index.php

DirectoryIndex index.php index.html

php.ini 和 php-fpm.ini 文件位于:

/usr/local/etc/php/7.2/

f。重新启动 Apache 服务

$ sudo apachectl restart

克。检查 php 版本:

$ php -v
PHP 7.2.7 (cli) (built: Jun 22 2018 06:29:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

完成!

请访问文章“Upgrade PHP version from 5.6 to 7.2 on macOS Sierra (10.12)” 了解更多信息!

加油!