Homebrew PHP version switcher is a simple script to switch between homebrew installed php versions for users using macOS.
This script is working only on macOS and it was tested only on Monterey. It may work on Big Sur and even older versions like Catalina and Mojave but you have to use it caution.
For best experience use Homebrew Apache 2.x version instead of macOS built-in Apache.
This script will automatically detect which php versions are installed on your machine via homebrew
To install legacy php versions (like 5.6) you can use shivammathur/homebrew-php.
git clone [email protected]:gtsvetanov/brew-php-switcher.git ./
cd brew-php-switcher
chmod +x brew-php-switcher.sh
mv brew-php-switcher.sh /usr/local/bin/brew-php-switcher
brew-php-switcher <version> [-a | -f | -v | -h]
-a|--apache
- This option will change your Apache 2.x configuration
# Setting CLI php version 8.1 and change Apache configuration to use the same version
brew-php-switcher 8.1 -a
-f|--fpm
- This option will change your PHP-FPM configuration
# Setting CLI php version 8.1 and PHP-FPM to use the same version
brew-php-switcher 8.1 -f
-v|--valet
- This option will change your Laravel Valet configuration
# Setting CLI php version 8.1 and Laravel Valet to use the same version
brew-php-switcher 8.1 -v
-h|--help
- This option will print help message
# Prints help message
brew-php-switcher -h
# Changes CLI / Apache / PHP-FPM and Laravel Valet to 5.6
brew-php-switcher 5.6 -a -f -v
# Changes CLI / Apache / PHP-FPM and Laravel Valet to 7.0
brew-php-switcher 7.0 -a -f -v
# Changes CLI / Apache / PHP-FPM and Laravel Valet to 7.1
brew-php-switcher 7.1 -a -f -v
# Changes CLI / Apache / PHP-FPM and Laravel Valet to 7.2
brew-php-switcher 7.2 -a -f -v
# Changes CLI / Apache / PHP-FPM and Laravel Valet to 7.3
brew-php-switcher 7.3 -a -f -v
# Changes CLI / Apache / PHP-FPM and Laravel Valet to 7.4
brew-php-switcher 7.4 -a -f -v
# Changes CLI / Apache / PHP-FPM and Laravel Valet to 8.0
brew-php-switcher 8.0 -a -f -v
# Changes CLI / Apache / PHP-FPM and Laravel Valet to 8.1
brew-php-switcher 8.1 -a -f -v