I have several PHP bash functions that come in handy every day when working on my M1 Mac. These functions help me in several ways:
php74
,php80
,php81
,php82
and so forth allow me to run any PHP version without unlinking and relinking the working version of PHP.phpv
allows me to change the working version of PHP on-the-fly.phpd
allow me to quickly enter debug mode in Xdebug for any version of PHP.phpdebug
allows me to enter debug mode in Xdebug for the working version of PHP.phpkill
allow me to end allphp-fpm
processes.
# php by version with homebrew install version
function php72() { /opt/homebrew/opt/[email protected]/bin/php "$@" }
function php73() { /opt/homebrew/opt/[email protected]/bin/php "$@" }
function php74() { /opt/homebrew/opt/[email protected]/bin/php "$@" }
function php80() { /opt/homebrew/opt/[email protected]/bin/php "$@" }
function php81() { /opt/homebrew/opt/[email protected]/bin/php "$@" }
function php82() { /opt/homebrew/opt/[email protected]/bin/php "$@" }
# php switch to homebrew install version
# > phpdebug artisan migrate:up
function phpv() {
brew unlink php
brew link --overwrite --force "php@$1"
php -v
}
# php current version with xdebug options
# > phpdebug artisan migrate:up
function phpdebug() {
php -v
XDEBUG_MODE=debug XDEBUG_SESSION=1 php "$@"
}
# php version with xdebug options
# > phpd 80 artisan migrate:up
function phpd() {
if [[ "$1" =~ ^[0-9]+$ ]]; then
php$1 -v
XDEBUG_MODE=debug XDEBUG_SESSION=1 php$1 "${@:2}"
else
echo "A PHP version number is required: 74, 80, 81, 82"
fi
}
# kill all php-fpm processes
# > phpkill
function phpkill() { sudo killall php-fpm }
Note, If you are coming from my previous article on running multiple versions of PHP on macOS you may need to unalias
the simpler versions of php74, php80, php81, and so on.
Leave a Reply