1

I need to execute a PHP file with another PHP version as installed. I know the full path to the other versions, but I do not know how to use it.

I have read the PHP man page but there is no mention of it. I assume I have to set the version first and then run it.

I know how to do it via htaccess, but isn't there a way to set the version directly in the command line?

3
  • See this SO question and answer.
    – jasonwryan
    Commented Sep 19, 2014 at 7:39
  • Thanks! The last answer in your link is telling only a solution via scripts/PHP files. So did I understand it right, you can't just start your script with another PHP version on the fly (or almost on the fly) via console?
    – Owl
    Commented Sep 19, 2014 at 7:41
  • No idea; I understood the answers to suggest that it wasn't really possible, but I know SFA about PHP...
    – jasonwryan
    Commented Sep 19, 2014 at 7:46

1 Answer 1

3

If you want to run a php-script on the command-line, you should use a shebang pointing to the absolute path. A shebang is the first line in a script telling the shell which program to use to execute it:

#!/path/to/your/alternative/php

then make your script executable and just run it:

chmod +x yourscript.php
./yourscript.php

Or you just call it directly with the binary of your alternative php-version:

/path/to/your/alternative/php yourscript.php
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .