Valet Linux+

Switching PHP version

Valet Linux+ can switch the global PHP version used to serve your sites with the valet use command. Supported versions are 8.2, 8.3, 8.4 and 8.5.

Warning

Valet installs PHP versions from your distribution's repositories. Make sure the repository that provides the desired version is configured before running valet use.

Repository for Ubuntu

bash
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Repository for Arch Linux

Edit /etc/pacman.conf and add the following (the order of repositories in pacman.conf matters, since pacman always downloads the first package found):

ini
[home_el_archphp_Arch]
Server = https://download.opensuse.org/repositories/home:/el:/archphp/Arch/$arch

Source: AUR — php83.

Switching PHP versions

bash
valet use {version}

Replace {version} with 8.2, 8.3, 8.4 or 8.5. For example:

bash
valet use 8.3

Run valet use without arguments (or valet use default) to go back to the PHP version that runs Valet's CLI.

When switching, Valet installs PHP-FPM for the selected version along with a common set of extensions: cli, mysql, gd, zip, xml, curl, mbstring, pgsql, intl and posix.

Setting the default CLI version

Besides switching the version used by the web server, you can also set the default PHP CLI version with --update-cli:

bash
valet use {version} --update-cli

For example, to make PHP 8.4 the default CLI version:

bash
valet use 8.4 --update-cli

Options

Option Description
--update-cli Also update the default PHP CLI version
--ignore-ext Skip installing the common PHP extensions for the selected version

Example commands

bash
valet use 8.2                 # Switch to PHP 8.2
valet use 8.5                 # Switch to PHP 8.5
valet use 8.3 --update-cli    # Switch to PHP 8.3 and make it the CLI default

Using older PHP versions

Note

To use older PHP versions such as 7.0, 7.1, 7.2, 7.3, 7.4, 8.0 or 8.1, use the valet isolate command. It isolates specific sites to a PHP version without changing the global one.

For example, to isolate a site to PHP 7.4, go to the site's directory and run:

bash
valet isolate [email protected]

The site will use PHP 7.4, while the rest of your environment keeps using the global PHP version. See Isolate PHP Version.