To install PHP 8 alongside PHP 7.4 and have it in a sibling directory (e.g., /opt/homebrew/etc/php/8.0 or /opt/homebrew/etc/php/8.1), follow these steps:
1. Add the shivammathur/php Tap:
First, you need to add the shivammathur/php tap to access older PHP versions, including PHP 8.x.
brew tap shivammathur/php
2. Install PHP 8.1 (or PHP 8.0):
To install PHP 8.1, use the following command:
brew install shivammathur/php/php@8.1
This will install PHP 8.1 and place its configuration and binaries in a sibling directory to PHP 7.4, such as /opt/homebrew/etc/php/8.1.
If you prefer PHP 8.0, run:
brew install shivammathur/php/php@8.0
3. Check the Installation Location:
You can check where PHP 8 is installed with the following:
brew info php@8.1
This will show you the location of PHP 8.1, which should be something like /opt/homebrew/etc/php/8.1 if you are using Homebrew installed in /opt/homebrew.
4. Switch Between Versions:
You can now use the brew unlink and brew link commands to switch between PHP 7.4 and PHP 8.
- To switch to PHP 8.1:
brew unlink php@7.4brew link php@8.1 --force --overwrite- To switch back to PHP 7.4:
brew unlink php@8.1brew link php@7.4 --force --overwrite
Now, PHP 7.4 and PHP 8.x will reside in sibling directories, and you can easily switch between them.
Leave a Reply