This zsh plugin will read .valetphprc
from the project root and will switch to that PHP version automatically real time. So php artisan
& composer
commands will always run on the project's PHP version when you are using Valet's site isolation feature!
Here's a quick video demonstration
CleanShot.2022-03-15.at.13.32.49.mp4
- Clone this repository in oh-my-zsh's plugins directory:
git clone https://github.com/NasirNobin/zsh-valet ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-valet
- Activate the plugin in
~/.zshrc
:
plugins=( [plugins...] zsh-valet)
- Create a file named
.valetphprc
in your project directory with following project's PHP version. Example:
php@8.1
- Optionally, You can define a default PHP version on your
.zshrc
. This will be used to reset PHP Binary when you exit a project directory. (Make sure to put before theplugins=( [plugins...] zsh-valet)
block)
VALETPHPRC_DEFAULT_PHP=php@8.0
- Restart zsh (such as by opening a new instance of your terminal emulator). Now when you cd into your project directory. It should automatically swap to .valetphprc defined PHP binary for that session.
Simply clone this repository and source the script:
git clone https://github.com/NasirNobin/zsh-valet
echo "source ${(q-)PWD}/zsh-valet/zsh-valet.plugin.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
If you want to show the PHP version change add this to your ~/.zshrc
.
export VALETPHPRC_SHOW_PHP_VERSION_CHANGE=1
If for some reason this plugin doesn't work with your environment. We recommend you uninstall your PHP versions and reinstall with the following method.
brew tap shivammathur/php
# install your required php versions
brew install shivammathur/php/php@8.1
brew install shivammathur/php/php@8.0
brew install shivammathur/php/php@7.4
brew install shivammathur/php/php@7.3
brew install shivammathur/php/php@7.2
brew install shivammathur/php/php@7.0
brew install shivammathur/php/php@5.6
This is still very early version of this plugin. If you see any issues, please open an issue on this repository. Also this seems to work fine on my M1 Mac, I still haven't tested it on Intel Mac (i think homebrew stores the php binary in a different directory on Intel Mac, so it might not work there yet)