Skip to content

Instantly share code, notes, and snippets.

@altynbek07
Last active March 25, 2022 22:42
Show Gist options
  • 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 [email protected] 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 [email protected] [email protected] [email protected]
    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
@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 [email protected]

@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