Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bradsi's avatar

How to Specify PHP CLI Version for Custom Console Commands

I have multiple projects on one server, all of them are on PHP 7.4 but I've recently upgraded one to PHP 8.1 however I've ran into an issue with my custom console commands.

For example, in Console/Kernel.php I have:

$schedule->command('jobs:email')->daily()->timezone('Europe/London')->at('06:00');

I need to set the PHP version dynamically based on the project that is running this. So my project that's on PHP 8.1 needs to use the PHP 8.1 CLI all the other projects need to use the PHP 7.4 CLI

Is this possible?

Just for completeness, I've tried running the commands manually and I get the following error message:

Composer detected issues in your platform:

Your Composer dependencies require a PHP version ">= 8.1.0". You are running 7.4.3.

PHP Fatal error:  Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 7.4.3. in /var/www/rmguk.com/api/vendor/composer/platform_check.php on line 24
0 likes
1 reply
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

I assume you are using a cron job. In there you can give it the path to the php executable to use

* * * * * cd /path-to-your-project &&/path/to/php8.1 artisan schedule:run >> /dev/null 2>&1

and the same goes for artisan directly

/path/to/php8.1 artisan
1 like

Please or to participate in this conversation.