How to Reinstall Homebrew PHP after the move from homebrew/php to homebrew/core

I remember hearing that homebrew/php was going to be deprecated and migrated to homebrew/core, but I forgot somewhere along the way until I started to update my Brew setup last week. I received a few issues with the automatic homebred-php migration. I am not positive, but I think it had to do with the fact that I had also installed php71-mcrypt. After doing some research, realized that php-mcrypt and other extensions that were optional with homebrew/php are included in the homebrew/core version of PHP. Homebrew logo

Below is what I did to clean up my setup, with details on each step. Note that I currently run PHP 7.1, for Drupal 7 compatibility, but PHP 7.2 is also available.

  • Completely uninstall the homebrew/php install
    • $ brew uninstall --force php@7.1
  • Un-tap homebrew-php since we will not be needing it any longer
    • $ brew untap homebrew/php
  • Next, I ran some brew commands to cleanup dead symlinks and older installs. This is a Brew wide operations, so completely optional if you don’t want to do this part.
    • $ brew prune && brew cleanup
  • Update Homebrew and formulae
    • $ brew update
  • Install the homebredw-core version of PHP 7.1
    • $ brew install php71
  • You can get details on the new PHP setup by running the following
    • $ brew info php71
  • I wanted make sure that Brew version of PHP is in my $PATH and I ran the following commands suggested via brew info php71 to set this up in my .zshrc. This can be altered for
    • $ echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.zshrc
    • $ echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.zshrc
    • $ source ~/.zshrc
  • When running php , I received warnings about the expected PHP mcrypt module not being found. I realized that references were probably left in my php.ini files form the old php71-mcrypt install. Since I didn’t have any specific details in my php.ini files that I needed to retain, I removed the Homebrew PHP configuration files and reinstalled PHP with the following. You may want to backup the config before doing this just in case you need to restore some configuration details (Directory to backup /usr/local/etc/php)..
    • $ rm -rf /usr/local/etc/php
    • $ brew reinstall php@7.1

After following the above steps, I have a well running Homebrew based PHP install for version 7.1. I have reproduced this on two Macs running macOS 10.13.4, so I wanted to document this in case it helps others.

Blog Category: