Isolating PHP versions
Valet Linux+ lets you isolate specific sites to run on a different PHP version without changing the global PHP version. This is useful to keep older projects running or to test against several PHP versions.
Isolation supports PHP 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 and 8.5.
Isolating a site
valet isolate {phpVersion} --site={siteName} --secure
{phpVersion}— The PHP version to use (e.g.[email protected],[email protected], or simply7.4).--site=(optional) — The site to isolate. Defaults to the current working directory.--secure(optional) — Serve the isolated site over HTTPS.
Example — isolate a site to PHP 7.4 and secure it:
valet isolate [email protected] --site=example --secure
From inside the site's directory:
valet isolate [email protected] --secure
Using a .valetphprc file
Add a .valetphprc file to the project root containing the PHP version (e.g. [email protected]). When you run valet isolate without a version, Valet reads it from that file:
echo "[email protected]" > .valetphprc
valet isolate
Listing isolated sites
valet isolated
Displays every isolated site, whether it is secured, and the PHP version it uses.
Removing isolation
valet unisolate --site={siteName}
--site=(optional) — The site to remove isolation from. Defaults to the current working directory.
Example:
valet unisolate --site=example
From inside the site's directory:
valet unisolate
Running PHP and Composer with the isolated version
When you accepted linking Valet's PHP helper during valet install, the php command (/usr/local/bin/php) automatically uses the isolated PHP version inside an isolated site's directory, and the default version anywhere else.
You can also be explicit:
valet php -v # PHP of the current directory's site
valet php --site=example artisan # PHP of a given site
valet composer install # Composer with the site's PHP
valet composer --site=example update
valet which-php # Print the PHP executable path for the current site
valet which-php example