0

Our app runs Stata CLI via PHP on different environments but we are having a hard time determining the path of the executable on different environments.

On a Mac using stata-mp works, while on a different Mac we have to use /usr/local/bin/stata-mp; on the Linux machine instead we need /usr/local/stata/stata-mp. Only the Linux environment used to be different than Mac, but now for some reason we can’t figure out also the Macs are different. The odd thing is that on Terminal/Shell stata-mp still works for both Macs AND the Linux server...

This is essentially the PHP code we use to execute our Stata script:

$return = exec(static::STATA . " -e do script.do ", $output, $result);

How can we correctly define the Stata path at runtime?

Using Stata MP v16.1

Stefano
  • 555
  • 1
  • 5
  • 18

1 Answers1

0

Normally is associated with your $PATH variable.

Try to do this:

$ php -a
$ var_dump($GLOBALS);

This will output your $GLOBALS environment on your shell. So you need to find a line with this:

["PATH"]=>
      string(168) "/home/william/.nvm/versions/node/v14.2.0/bin:/home/william/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

This config will show where your php-cli will search to execute your command.

Now, try to search where your stata-mp is located with this command:

whereis vim

And check if your PATH contains the path of your command. If does not, you can put on your .bashrc to your script understand on the next file read or, you can set on your script call. (It depends on your shell but, in Mac, you can check here about the PATH env.

William Prigol Lopes
  • 1,803
  • 14
  • 31
  • thanks @william, but I would expect STATA to have a default path I could use, maybe depending on the OS type (I used `PHP_OS_FAMILY` so far) or something, so I could not depend on PATH, which kinda depends on the actual machine. Does that makes sense? – Stefano Jun 09 '20 at 23:43
  • This `PATH` is got from the `$PATH` of your OS shell so, the PHP will already get from your OS. Try to open the terminal and execute the same line that you're trying on your execute in PHP and see if it works, probably, where the PHP script don't run, you will cannot call the stata from shell already. – William Prigol Lopes Jun 09 '20 at 23:51
  • as I mentioned, in shell/terminal `stata-mp` works on all the environments, but when executing the commands via PHP the same Sata command is not found. It seems that the shell/terminal environment is not the same as the PHP environment, so the `PATH` value is different, for some reason – Stefano Jun 10 '20 at 00:01
  • Could be the user that you're using (if you installed STATA only on your user and executes the PHP with another user, the another user could not "see" the stata. In the past I had some issues with this using CPLEX. Installed globally and everything fine – William Prigol Lopes Jun 10 '20 at 00:12