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?

  • See this SO question and answer. – jasonwryan Sep 19 '14 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 Sep 19 '14 at 7:41
  • No idea; I understood the answers to suggest that it wasn't really possible, but I know SFA about PHP... – jasonwryan Sep 19 '14 at 7:46

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:


then make your script executable and just run it:

chmod +x yourscript.php

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.