Skip to content

Instantly share code, notes, and snippets.

@vlados
Created March 26, 2022 21:44
Show Gist options
  • Select an option

  • Save vlados/211c9136a05464b7ffbcc99ccc3a254f to your computer and use it in GitHub Desktop.

Select an option

Save vlados/211c9136a05464b7ffbcc99ccc3a254f to your computer and use it in GitHub Desktop.
Simple function to do everything needed to switch easily php version

Switch PHP Version in Laravel Valet

Simple function to do everything needed to switch easily php version

Install

Add this function in your .zshrc file:

# Switch PHP version
switch-php() {
    readonly port=${1:?"Please specify php version"}
    valet use php@$1
    brew link --force --overwrite php@$1
    brew services restart php@$1
    echo -n > ~/.switch-php
    echo 'export PATH=''"/usr/local/opt/php@'$1'/bin:$PATH"' >> ~/.switch-php
    echo 'export PATH=''"/usr/local/opt/php@'$1'/sbin:$PATH"' >> ~/.switch-php
    composer global update
    omz reload
    source ~/.switch-php
    php -v
}

Usage

Switch to PHP version

switch-php version
# example switch-php 8.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment