【问题标题】:Unable to install PHP 7 with Homebrew on macOS Sierra无法在 macOS Sierra 上使用 Homebrew 安装 PHP 7
【发布时间】:2016-09-21 20:46:37
【问题描述】:

我正在尝试设置 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 许可协议。

我不知道这些错误是什么意思。我该如何解决?

【问题讨论】:

    标签: php homebrew macos-sierra


    【解决方案1】:

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

    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
    

    【讨论】:

    • 给出错误:homebrew/php 已被弃用。这个水龙头现在是空的,因为它的所有公式都被迁移了。看起来他们已经移动了 homebrew/php/php70。
    【解决方案2】:

    对于那些通过 Homebrew 使用 macOS 提供的 Apache 和 PHP 安装的用户来说,这也很重要(引用自 Homebrew php70 install):

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

    【讨论】:

    • 现在不推荐使用--with-apache 选项,请改用--with-httpd24
    【解决方案3】:

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

    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
    

    【讨论】:

      【解决方案4】:

      这是我在 Macbook Pro (macOS Sierra) 中将 PHP 5.6 升级到 7.2 的方法

      一个。先更新brew包。

      $ brew update && brew upgrade
      

      b.如果使用 Homebrew 安装旧版本的 PHP,请取消链接。

      $ 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
      

      g.检查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)” 更多信息请访问我的博客!

      加油!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-06-19
        • 2018-11-03
        • 2017-04-19
        • 2017-06-16
        • 1970-01-01
        • 2017-06-14
        • 2022-12-04
        • 2017-05-30
        相关资源
        最近更新 更多