Failed to install PHP 7 with Homebrew on macOS Sierra

I am trying to configure Laravel Valet, which, as a dependency, requires PHP 7. When I try to install PHP 7 with Homebrew, I get the following error:

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 the new version of macOS Sierra (actual version, not beta) with a fresh installation of Homebrew (updated). I installed, launched and agreed to the Xcode license agreement.

I have no idea what these errors mean or how to fix them. Can anyone help?

Thanks.

+5
source share
3 answers
That's right, I figured it out. I post the steps for successfully installing the required components below in case anyone else stumbles upon this problem:

1). make sure Homebrew is updated:

 brew update 

2). Correct the PHP 7 error by making sure Xcode is installed, and then enter the following into the terminal:

 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). Run the following command (otherwise the PHP installation will complain about the lack of libz):

 xcode-select --install 

4). Now you can install PHP 7 using Homebrew:

 brew install homebrew/php/php70 
+9
source

It may also be important for those using the MacOS-supplied Apache installation with PHP via Homebrew, which (quote from Homebrew php70 install):

With the release of macOS Sierra, the Apache module is no longer built by default. If you want to create it on your system, you need to install php with the --with-apache option. See brew php70 options for more details.

+2
source

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 
+1
source

All Articles