Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jan_zikmund's avatar

PHP 7.4 on Laravel Valet 3.1

I've setup local dev environment on Laravel Valet 3.1. Ideally I would like to have two versions of PHP - 7.4 and 8.1, where 7.4 would be the default. I am just somewhat confused about some points, can someone please clarify if I am not doing something wrong?

  1. Is there currently any use for valet use [email protected] and similar? Valet 3.1 requires PHP 8.1, which imo is latest. So if I use this command, it downgrades PHP to 7.4, but then valet use [email protected] or pretty much any valet command crashes on error about requires PHP version. My only way is to brew unlink [email protected] and brew link [email protected] to get valet back working.

  2. So from the above, it looks like currently only way to have valet working properly is to have [email protected] as default, older version cannot be default, is that correct?

  3. Having [email protected] as default, I have set [email protected] to some sites using isolate command. Unfortunately that requires to always prefix php commands with valet, eg. valet php artisan make:model. It's good that there is this way, but it is somewhat tedious to do always. Also for running PHPUnit tests I have to do something like valet php ./vendor/bin/phpunit. Is there any better way to perhaps alias php command to valet php for the sites which are isolated, or any walkaround that would make it more convenient?

Thanks so much

0 likes
2 replies
jan_zikmund's avatar

@snapey - thanks, I have tried it and I can confirm it has no trouble switching global PHP version there and back without any issues. Also the overview panel looks nice, so I can recommend.

Still, I was rather looking for a permanent solution which I can set up once and won't need to do any more switching later. Looks like in the end pure Valet does it just fine, I just have to keep my default PHP on 8.1, isolate sites that I want on 7.4 and in my zsh aliases add alias php="valet php". That will make sure that in any sites' folder isolated on @7.4 I get that PHP even on command line. So I can call php artisan and similar normally.

For PHPUnit, I just wrote a quick shell function, which I also put in ZSH aliases. It checks if phpunit binary is in vendor dir, and if it does, it calls it through actual php version:

pu() {
	FILE=./vendor/bin/phpunit
	if [ -f "$FILE" ]; then
	    php $FILE "$@"
	else 
	    phpunit "$@"
	fi	
}

So far this looks like what I need, I will see where the real world takes me 🤓 🙂

Please or to participate in this conversation.