1

I am using SublimeText3 on OSX. The problem is:

  • If I execute PHP script on SublimeText3, then it is executed by PHP 5.5.
  • But if I execute the same script from shell (iTerm), then it is executed by PHP 7.

How can I execute a script with PHP7 on SublimeText3?

The build system is following.

{
    "cmd" : ["php", "$file"],
    "file_regex": "php$",
    "selector"  : "source.php"
}

And the PHP script is just:

<?php
phpinfo();
?>
H. Shindoh
  • 906
  • 9
  • 23
  • 1
    Under OSX the path as seen by GUI applications like Sublime and the path that the terminal sees are not necessarily the same, so the terminal may be finding a different php executable. You can specify a path in the build system or put an explicit path on the php that your build system is executing to ensure it picks the right one. – OdatNurd Oct 12 '16 at 17:06

1 Answers1

3

Specify the absolute path to the command (cmd).

Let's say $file is /path/to/file, then the command ['php', "$file"] expands to php /path/to/file. This is like running the following on the command line:

$ php /path/to/file

Because the command (php ) is relative, the system path (on linux the system path is in the environment variable PATH) is searched to find php.

You can specify an absolute path for the command. Let's say you have the following versions installed:

  • /path/to/php/versions/7.0.0/bin/php
  • /path/to/php/versions/5.5.0/bin/php

Then you can configure a command to use v7.0.0:

{
    "cmd" : ["/path/to/php/versions/7.0.0/bin/php", "$file"],
    "file_regex": "php$",
    "selector"  : "source.php"
}

And v5.5.0:

{
    "cmd" : ["/path/to/php/versions/5.5.0/bin/php", "$file"],
    "file_regex": "php$",
    "selector"  : "source.php"
}

And so on...

Further reading

Gerard Roche
  • 6,162
  • 4
  • 43
  • 69