php
php8
I prefer this over brew solutions with link
and unlink
.
# Install php (defaults to version 8).
brew install php
# Install older php 7.4.
brew install php@7.4
# Unlink php8.
brew unlink php
# Double check php 7.4 is linked (this will set php7.4 as the default)
brew link php@7.4
# Create a symlink in /usr/local/bin.
ln -s /usr/local/opt/php/bin/php /usr/local/bin/php8
$PATH
setups in your .bashrc
or .zshrc
(or equivelent). It may look like this.
# .bashrc or .zshrc or equivelent
# Remove this line!
export PATH="/usr/local/opt/php@7.4/bin:$PATH"
# Install php (defaults to version 8).
pamac install php
# Install older php 7.4.
pamac install php74
# Setup php 8 as the version to be used when you run "php8".
sudo ln -s /usr/bin/php /usr/local/bin/php8
# Setup php 7.4 as the default version to be used.
sudo ln -s /usr/bin/php74 /usr/local/bin/php
Output of php -v
$ php -v
PHP 7.4.27 (cli) (built: Dec 16 2021 18:14:46) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.27, Copyright (c), by Zend Technologies
Output of php8 -v
$ php8 -v
PHP 8.1.1 (cli) (built: Jan 8 2022 08:25:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies