Managing multiple PHP versions with Laravel Valet is great β until you type php -v and get the global version instead of the one Valet set for that directory.
Legacy projects that need Composer v1 don’t play well with the v2 you have globally.
A few lines of fish config fix both. php, composer, and phpunit all follow Valet automatically.
The Problem
Valet’s valet php command runs PHP using the version configured for the current directory. But typing php directly uses the system-wide PHP β completely unrelated to Valet.
Composer is worse: some older packages are incompatible with Composer v2 and need v1 to install. You can’t downgrade your whole system’s Composer for one legacy project. The workaround is dropping a composer.phar (v1) in the project directory β but then you have to remember to type php ./composer.phar every time. Annoying.
The Fish Config
Add this to ~/.config/fish/config.fish:
| |
Run source ~/.config/fish/config.fish or restart your terminal to apply.
What Each Line Does
alias php "valet php"
valet php picks the PHP version based on the current directory’s .valetphprc or Valet’s per-directory configuration. With this alias, php artisan, php -v, and everything else automatically uses the right version β no manual switching.
alias phpunit "php vendor/bin/phpunit"
PHPUnit is a PHP script, so which PHP runs it matters. This alias ensures phpunit uses php (which is now valet php), keeping it in sync with the project’s PHP version.
function composer
This function solves Composer v1/v2 coexistence:
| |
[ -n "./composer.phar" ] checks whether composer.phar exists in the current directory. If it does, use it (v1); otherwise fall back to valet composer (v2).
COMPOSER_MEMORY_LIMIT=-1 removes the memory cap. Composer v1 runs out of memory easily on complex dependency trees. v2 is far more efficient and rarely needs this.
$argv passes all arguments through, so composer install, composer require laravel/framework, and everything else works normally.
Setting Up a Legacy Project for Composer v1
When you hit a project that needs v1, download composer.phar into the project root:
| |
From that point on, composer install in that directory automatically uses v1. Every other project without a composer.phar continues using v2. They don’t interfere with each other.
Verifying the Setup
| |
Summary
The core idea: let development tools follow Valet’s PHP version automatically instead of managing it manually. php and phpunit are simple aliases. composer needs a function because of the v1/v2 coexistence requirement.
Dropping composer.phar in a project root acts as a flag β “this project needs v1.” No extra config files, no environment variables, just a file that’s already there for a reason.
