I prefer this over brew solutions with
Install both the default php package 8.1 and the older php7.4 / php8.0 packages
# Install php (defaults to version 8). brew install php # Install older php 7.4. brew install firstname.lastname@example.org # Install older php 8.0. brew install email@example.com
Make php 8.0 the default
# Unlink php8.1 brew unlink php # Unlink php7.4 brew unlink firstname.lastname@example.org # Link php8.0 Double check php 7.4 is linked (this will set php8.0 as the default) brew link email@example.com
Create extra symlinks for php 7.4 and 8.1
# Create a symlinks in /usr/local/bin. You will likely have to run sudo. ln -s /firstname.lastname@example.org/bin/php /usr/local/bin/php81 ln -s /email@example.com/bin/php /usr/local/bin/php7
(bonus) Setup composer shortcuts to run composer with specific php versions.
# .bashrc or .zshrc or equivalent alias composer7='php7 /usr/local/bin/composer' alias composer81='php81 /usr/local/bin/composer'
Remove any manual php
$PATH setups in your
.zshrc (or equivalent). It may look like this.
# .bashrc or .zshrc or equivalent # Remove any lines like this! export PATH="/firstname.lastname@example.org/sbin:$PATH" export PATH="/email@example.com/bin:$PATH"
# Install php (defaults to version 8). pamac install php # Install older php 7.4. pamac install php74
# Setup php 7 as the version to be used when you run "php7". sudo ln -s /usr/bin/php74 /usr/local/bin/php7
$ php -v PHP 8.0.22 (cli) (built: Aug 4 2022 10:20:33) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.22, Copyright (c) Zend Technologies with Zend OPcache v8.0.22, Copyright (c), by Zend Technologies
$ php7 -v PHP 7.4.30 (cli) (built: Jun 9 2022 09:20:03) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies
$ php81 -v PHP 8.1.9 (cli) (built: Aug 4 2022 14:00:20) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.9, Copyright (c) Zend Technologies with Zend OPcache v8.1.9, Copyright (c), by Zend Technologies