Saturday, March 4, 2023

Use multiple php version using valet

 To use multiple PHP versions with Valet on a Mac, you will need to follow these steps:

Install the desired versions of PHP using Homebrew. For example, to install PHP 7.4 and 8.0:

brew install php@7.4

brew install php@8.0

Install Valet if you haven't already:

composer global require laravel/valet

valet install

Install Valet's PHP switcher plugin:

valet install

valet use php@7.4

Create a symbolic link for each version of PHP that you installed. For example:

sudo ln -s /usr/local/opt/php@7.4/bin/php /usr/local/bin/php74

sudo ln -s /usr/local/opt/php@8.0/bin/php /usr/local/bin/php80

Run the following command to add the newly created symbolic links to your $PATH environment variable:


echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

source ~/.bash_profile

Restart Valet:

valet restart

You can now switch between PHP versions using the valet use command. For example, to use PHP 7.4:

valet use php@7.4

To switch back to PHP 8.0:


valet use php@8.0

Note that you will need to install any required PHP extensions for each version of PHP that you use. You can install extensions using Homebrew or by manually compiling and installing them.

No comments:

Post a Comment