Composer scripts and Valet isolate

Something to be aware of

Joel Clermont
Joel Clermont

We typically set up projects with a Docker Compose configuration, but sometimes if we're temporarily joining a project, we'll instead use Valet.

One nice feature in Valet is the ability to lock a site to a particular version of PHP. Through the valet isolate command, you can have one site running on PHP 8.2 even if your system default is running on PHP 8.3.

But you have to be careful in how you define your Composer scripts. If your scripts call binaries directly (like phpunit), composer will run the script under the system default PHP, not your isolated version.

To get around this, you can use the @php prefix in your Composer script definitions. According to Composer's docs, "@php will automatically resolve to whatever process is currently being used." This is exactly what we want:

    "scripts": {
        "test": "@php phpunit"

Here to help,


P.S. Don't leave security as an afterthought. We've packaged up a few security-focused tips for your Laravel app.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼

Level up your Laravel skills!

Each 2-minute email has real-world advice you can use.