Skip to content

Instantly share code, notes, and snippets.

@bgarrant
Last active September 30, 2022 08:08
Show Gist options
  • Save bgarrant/b9a2f7fb8ff06c9a45086359ded7a95e to your computer and use it in GitHub Desktop.
Save bgarrant/b9a2f7fb8ff06c9a45086359ded7a95e to your computer and use it in GitHub Desktop.
How to Switch PHP Version in Laravel Valet between PHP 7.1 and PHP 5.6

How to Switch PHP Version in Laravel Valet between PHP 7.1 and PHP 5.6

Valet switch PHP version with these commands

Install PHP 5.6 and switch Valet to PHP 5.6

valet stop
brew unlink php71
brew install php56
brew install php56-mcrypt
brew link php56
valet start

Then to switch back to PHP 7.1 it is as simple as:

valet stop
brew unlink php56
brew link php71
valet start

Then to switch to PHP 5.6:

valet stop
brew unlink php71
brew link php56
valet start
@opdavies
Copy link

Had the same thing, had to remove the global composer.lock file and vendor directory, and then re-required it.

$ rm -rf ~/.composer/composer.lock ~/.composer/vendor
$ composer global req laravel/valet

@altynbek07
Copy link

@wakjoko
Copy link

wakjoko commented Jun 20, 2020

on Ubuntu or linux, put this in your .profile

#switch php version
switch-php() {
    valet stop
    sudo update-alternatives --set php /usr/bin/php$1
    rm -f ~/.valet/valet.sock
    valet install
}

then use it as switch-php 7.1 or switch-php 7.4

@davidtowoju
Copy link

One liner here, simply type this in your terminal

valet use php@7.2

@rafaellaurindo
Copy link

One liner here, simply type this in your terminal

valet use php@7.2

Aweeesome! Thank you for sharing it! 🚀

@faytekin
Copy link

faytekin commented Apr 7, 2021

you can use phpmon

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

@KevinDrew
Copy link

I had to do
valet use php@7.4 --force
without it, it only changed the cli, and phpinfo in the browser showed 8.0

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