Search code examples
macoshomebrewphp-7macos-sierraphp-7.1

Can't install php7 or php 7.1 with homebrew


I was following a couple links that had this same sequence, namely this example. I was unable to get it done successfully. Here is the output from terminal

MacBook-Pro-4:/ SHennessy$ brew tap homebrew/dupes
MacBook-Pro-4:/ SHennessy$ brew tap homebrew/versions
MacBook-Pro-4:/ SHennessy$ brew tap homebrew/homebrew-php
MacBook-Pro-4:/ SHennessy$ brew unlink php56
Error: No such keg: /usr/local/Cellar/php56
MacBook-Pro-4:/ SHennessy$ brew install php70
==> Installing php70 from homebrew/php
Error: You must `brew link libpng` before homebrew/php/php70 can be installed
MacBook-Pro-4:/ SHennessy$ brew link php70
Error: No such keg: /usr/local/Cellar/php70
MacBook-Pro-4:/ SHennessy$

If anybody has any ideas that would be awesome, thanks in advance.


Solution

  • For MacOS Monterey I faced a similar issue /usr/local/Cellar/php while switching between different php versions

    Following steps help me to fix my issue

    Step 1

    After installing php first link that particular version

    brew link [email protected] //Whatever you installed
    

    Step 2

    Switching to another php version use the following commands

    brew unlink [email protected] //Whatever is your current active version
    brew link --overwrite --force [email protected] //Whatever your desired version
    

    Or you can use single command

    brew unlink [email protected] && brew link --overwrite --force [email protected]