0

The latest version of PHP 8.1 is 8.1.17 right now, but for development reasons I need an older version. Specifically 8.1.6 to support development on our Ubuntu running servers, as well as to prevent some bugs occurring that have been introduced in the newer php versions.

How can I do this when brew installs the latest version by default? I also tried the shivammathur/php tap but it also just installs the latest version.

Shivam Mathur
  • 2,543
  • 19
  • 26
Lehren
  • 99
  • 2
  • 11
  • Does this answer your question? [How can I easily switch between PHP versions on Mac OSX?](https://stackoverflow.com/questions/34909101/how-can-i-easily-switch-between-php-versions-on-mac-osx) – Lelio Faieta Mar 24 '23 at 15:08

1 Answers1

1

To install an older PHP release, say 8.1.16 using the shivammathur/php tap you can follow these steps

  1. Go to the tap directory.
cd "$(brew --repo shivammathur/php)"
  1. Search for the commit with the PHP version, for 8.1.16 do
git log -p -S php-8.1.16
  1. Check the diff for each commit displayed and pick the commit hash where 8.1.16 was added to the tap and checkout to it. For 8.1.16 it is 1685cc93fccbf1f4a7d74cb876c5d0119d952b43.
git checkout 1685cc93fccbf1f4a7d74cb876c5d0119d952b43
  1. Reinstall PHP 8.1 using the tap.
brew reinstall -s shivammathur/php/php@8.1

To switch back to the latest version, restore the tap and reinstall PHP.

brew tap --repair shivammathur/php
brew reinstall shivammathur/php/php@8.1
Shivam Mathur
  • 2,543
  • 19
  • 26
  • Not all past PHP versions are in your repository so it doesn't solve it. You went from 8.1.0 straight to 8.1.13 – Lehren Mar 28 '23 at 12:04
  • If you check out the commit for versions between 8.1.0 and 8.1.13, those would be in `Formula/php.rb`. – Shivam Mathur Mar 28 '23 at 13:23
  • 1
    For switching back I had to completely reinstall php@8.1 brew uninstall --force php@8.1 brew install php@8.1 – Vaci May 19 '23 at 05:52