简体   繁体   English

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

[英]Unable to install PHP 7 with Homebrew on macOS Sierra

I'm trying to setup Laravel's Valet which, as a dependency, requires PHP 7. When I try to install PHP 7 with Homebrew I get the following error:我正在尝试设置 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

This is on a fresh install of MacOS Sierra (actual release, not a beta) with a fresh install of Homebrew (updated).这是全新安装的 MacOS Sierra(实际版本,不是测试版)和全新安装的 Homebrew(更新)。 I have installed, ran and agreed to the Xcode licensing agreement.我已经安装、运行并同意 Xcode 许可协议。

I have no idea what these errors mean.我不知道这些错误是什么意思。 How can I fix them?我该如何修复它们?

Right I've figured it out.没错,我已经想通了。 I'm posting the steps to successfully install the require components below in case anybody else stumbles upon this issue:我在下面发布了成功安装所需组件的步骤,以防其他人偶然发现此问题:

1). 1)。 make sure Homebrew is up to date:确保 Homebrew 是最新的:

brew update

2). 2)。 Fix the PHP 7 error by making sure Xcode is installed and then typing the following into the Terminal:通过确保 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). 3)。 Run the following command (otherwise the PHP installation will complain about missing libz):运行以下命令(否则 PHP 安装会抱怨缺少 libz):

xcode-select --install

4). 4)。 You can now install PHP 7 with Homebrew:您现在可以使用 Homebrew 安装 PHP 7:

brew install homebrew/php/php70

I used the following commands to make it work.我使用以下命令使其工作。

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

It may also be important for those using the macOS-delivered installation of Apache with PHP via Homebrew that (quote from Homebrew php70 install):对于通过 Homebrew 使用 macOS 提供的 Apache 和 PHP 安装的人来说,这也很重要(引用自 Homebrew php70 install):

With the release of macOS Sierra the Apache module is now not built by default.随着 macOS Sierra 的发布,Apache 模块现在不是默认构建的。 If you want to build it on your system you have to install php with the --with-apache option.如果你想在你的系统上构建它,你必须使用 --with-apache 选项安装 php。 See brew options php70 for more details.有关更多详细信息,请参阅 brew 选项 php70。

Here is how I upgrade PHP 5.6 to 7.2 in my Macbook Pro (macOS Sierra)这是我在 Macbook Pro (macOS Sierra) 中将 PHP 5.6 升级到 7.2 的方法

a. a. Update the brew package first.首先更新brew包。

$ brew update && brew upgrade

b.Unlink the old version of PHP if it was installed with Homebrew.如果旧版本的 PHP 与 Homebrew 一起安装,则取消链接。

$ brew unlink php56

c. C. Install the new version of PHP.安装新版本的 PHP。

$ brew install php72

After installation, it shows: To enable PHP in Apache add the following to httpd.conf (/etc/apache2) and restart Apache:安装后,显示: To enable PHP in Apache in httpd.conf (/etc/apache2) 添加以下内容并重新启动Apache:

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

$ sudo vim /etc/apache2/httpd.conf

Search “php5_module” then commend out the statements as follows:搜索“php5_module”,然后推荐如下语句:

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

Add the commands as follows:添加命令如下:

#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. e. Finally, check DirectoryIndex includes index.php最后,检查 DirectoryIndex 包括 index.php

DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in: php.ini 和 php-fpm.ini 文件可以在以下位置找到:

/usr/local/etc/php/7.2/

f. f. Restart Apache service重启Apache服务

$ sudo apachectl restart

g.克。 check the php version:检查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

Done!完成!

Please visit the article " Upgrade PHP version from 5.6 to 7.2 on macOS Sierra (10.12) " of my blog for more information!请访问我的博客文章“ 在 macOS Sierra (10.12) 上将 PHP 版本从 5.6 升级到 7.2 ”以获取更多信息!

Cheer!加油!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM