-1
php -v

gives 7.4

which php

gives 7.4

php test.php with the following test file:

<?php
echo phpversion();
?>

gives 7.4

But when I run the install/bootup script for Craft CMS, it's executing the file Bootup.php with PHP 5.6.

Under what circumstances will presumably a bash script default to an old php version? I suspect this could be an environment variable in Composer. And how do I get it to run using the desired one?

Apologies if I'm asking the xy question.

  • You can start composer with a specific PHP version using ` composer.phar `. You probably have the command `php` aliased to the newest version, but composer does not know about it. – paskl Oct 04 '20 at 16:38
  • @paskl in case you're interested I diagnosed the cause of the problem and have posted my solution as an answer https://stackoverflow.com/a/64198753/7799269 . Does your solution solve the problem explained in my answer, do you know? – it's a hire car baby Oct 04 '20 at 19:09
  • @NicoHaase yes Bernie's answer there covers my scenario. Thanks. https://stackoverflow.com/a/32752473/7799269 – it's a hire car baby Oct 05 '20 at 07:34

2 Answers2

0

Ok, so it turns out the php files in composer have the following shebang:

#!/usr/bin/env php

For some reason I don't fully understand, this has the effect of ignoring ALIAS and looking for the first php in $PATH instead.

So the solution I opted for was to find the first php in $PATH, rename it php2 and then using ln -s I made a link in that folder called php and pointed it to the correct php version binary, in my case ln -s /opt/plesk/php/7.4/bin/php php

Composer and Craft are now running with the desired php version.

-1

Check in composer.json file if you have set platform

"platform": {
        "php": "5.6"
    }

It's define your target platform you are going to use in project.

dajmund
  • 82
  • 5
  • Thanks for the suggestion. That said 7.0. but it turns out there was a #! Specifying /home/env php at the start of the file and this led it to the first php in $PATH . So I renamed that to php2 and used ls to point that php to php7. – it's a hire car baby Oct 04 '20 at 17:46
  • That does not help to run scripts with another version of PHP. This setting is only used to resolve dependencies tied to a specific version of PHP – Nico Haase Oct 05 '20 at 08:09