MacBook Pro affichant du code

macOS – Install PHP 7.4 and force its use

Start by installing homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

PHP 7.4 has been removed from homebrew-core. You need the tap that keeps the older versions

brew tap shivammathur/php
brew install shivammathur/php/php@7.4
brew link --force php@7.4
brew services start php@7.4
export PATH="/usr/local/opt/php@7.4/bin:$PATH"
export PATH="/usr/local/opt/php@7.4/sbin:$PATH"

On Apple Silicon, replace /usr/local/opt with /opt/homebrew/opt
Once this is done, check that the PHP version is correct

php -v
PHP 7.4.13 (cli) (built: Nov 30 2020 14:46:04) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies