Skip to content

Switching PHP version

Valet Linux Plus supports switching between different PHP versions using the valet use command. This allows you to easily switch your development environment to use PHP 8.2 or 8.3 as needed.

[!WARNING] Valet uses PPA to download different PHP versions make sure to have PPA added in your machine before using valet use command.

PPA for Ubuntu

sudo add-apt-repository ppa:ondrej/php

PPA for ArchiLinux

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

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

Source: https://aur.archlinux.org/packages/php83

Switching PHP Versions

To switch to a specific PHP version, use the following command:

valet use {version}

Replace {version} with either 8.2 or 8.3. For example, to switch to PHP 8.2, run:

valet use 8.2

Setting the Default CLI Version

In addition to switching the PHP version for your web server, you can also set the default PHP CLI version using the --update-cli option. This ensures that the specified PHP version is used for command-line scripts.

To set the default CLI version, use the command with the --update-cli option:

valet use {version} --update-cli

For example, to set PHP 8.3 as the default CLI version, run:

valet use 8.3 --update-cli

Example Commands

Switch to PHP 8.2:

valet use 8.2

Switch to PHP 8.3:

valet use 8.3

Set PHP 8.2 as the default CLI version:

valet use 8.2 --update-cli

Set PHP 8.3 as the default CLI version:

valet use 8.3 --update-cli

Using Older PHP Versions

Note: If you need to use older PHP versions such as 7.2, 7.3, 7.4, 8.0, or 8.1, use the valet isolate command. This command allows you to isolate specific sites to run on different PHP versions without changing the global PHP version.

For example, to isolate a site to use PHP 7.4, navigate to the directory of your site and run:

valet isolate 7.4

This command will ensure that the specific site uses PHP 7.4, while the rest of your environment remains on the globally set PHP version.