If you use Laravel Herd and PhpStorm, you may have noticed that the PHP set in PhpStorms config isn't being used in the terminal. Even though it's pointed to your e.g. php80 binary, when you enter php -v in PhpStorms terminal, you will get the default version set in Herd.

To solve this, we need to create a symbolic link that is named php pointed to the real binary you want to use, so that PhpStorm will understand how to magically "switch" the php binary used for the terminal.

This guide will assume you have PHP 8.1 installed and used as the default PHP-version in Herd, but for one project you want to use PHP 8.0.

Follow these steps (you will need to change these paths so they are correct for your own system):

  1. Create a new folder in Herds bin directory, e.g: mkdir "/Users/victor/Library/Application Support/Herd/bin/php8.0"
  2. Create a symbolic link to a new php binary, e.g: ln -s "/Users/victor/Library/Application Support/Herd/bin/php80" "/Users/victor/Library/Application Support/Herd/bin/php8.0/php"
  3. Enter PhpStorm settings (Cmd+,) and in the "PHP" section under "CLI intepreter", enter /Users/victor/Library/Application Support/Herd/bin/php8.0/php as the path for your "PHP executable". You may need to create a new CLI intepreter if you do not already have one for this specific version.
  4. Open another terminal in PhpStorm and voila, you're now using PHP 8.0 for this project :)

Do you know of a better way to solve this? Please let us know!