logo
podcast Podcast
get help Get Unstuck

Composer scripts and Valet isolate

Something to be aware of

Joel Clermont
Joel Clermont
2024-02-02

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,

Joel

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 👇🏼
email
No spam. Only real-world advice you can use.