Skip to content

Instantly share code, notes, and snippets.

@altynbek07
Last active March 25, 2022 22:42
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save altynbek07/2147e48ea1df9145a803c8245f5dc130 to your computer and use it in GitHub Desktop.
Save altynbek07/2147e48ea1df9145a803c8245f5dc130 to your computer and use it in GitHub Desktop.
Switch PHP Version in Laravel Valet

Switch PHP Version in Laravel Valet

For me, the valet use php@7.3 command does not work. And so I created this bash function.

Install

I already have PHP versions 7.2, 7.3 and 7.4 installed via Homebrew. Add this function in your .bash_profile or .zshrc file:

# Switch PHP version
switch-php() {
    valet stop
    brew unlink php@7.2 php@7.3 php@7.4
    brew link --force --overwrite php@$1
    brew services restart php@$1
    composer global update
    rm -f ~/.config/valet/valet.sock
    valet install
}

Then reboot your terminal.

Usage

Switch to PHP 7.4

switch-php 7.4

Switch to PHP 7.3

switch-php 7.3

Switch to PHP 7.2

switch-php 7.2

Version

  • macOS Catalina 10.15.6
  • Homebrew 2.4.8
@kienstra
Copy link

Thanks, this was really helpful. A simple valet use php@7.3 && valet restart didn't work for me.

@altynbek07
Copy link
Author

Thanks, this was really helpful. A simple valet use php@7.3 && valet restart didn't work for me.
👍🏻

@himak
Copy link

himak commented Apr 23, 2020

Thanks, its helpful for me, too ;)

@niltonmelox
Copy link

Very good!

@MarGul
Copy link

MarGul commented Jun 17, 2020

This was awesome. Thanks!

@ronssij
Copy link

ronssij commented Jul 5, 2020

image
I tried this, but I am running an error like this one.

@altynbek07
Copy link
Author

image
I tried this, but I am running an error like this one.

@ronssij Write me a personal message and I will help you. What messenger do you use?

@ronssij
Copy link

ronssij commented Jul 5, 2020

I wrote you on your email.

@egdavid
Copy link

egdavid commented Aug 18, 2020

Thanks for the tip, it helped!
For Valet Linux:

valet stop
rm -f ~/.valet/valet.sock
sudo update-alternatives --set php /usr/bin/php7.4 (or any version you wanna use)
valet install

@himak
Copy link

himak commented Oct 3, 2020

rm -f ~/.config/valet/valet.sock
valet use php@x.x

@faytekin
Copy link

faytekin commented Apr 7, 2021

you can use phpmon

brew tap nicoverbruggen/homebrew-cask
brew install --cask phpmon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment