I call an R script from PHP and it works well.  I just call it using this function

shell_exec("Rscript play.r");

To do that I had to set environment variables in Windows to the R executable be recognized by the OS.

Well now I am trying to do the same for Linux. I have the same error that I had on Windows before setting environment variables:

Rscript:not found 127

I think the Linux operating system is not finding the path to the R "executable" when I call it from PHP.

I think that I must to set the environment variables to R on Linux but I don't know how to do that.

What should I do?

1 Answer 1


You do not necessarily need to set environmental variables. Simply call Rscript by its full path:

shell_exec("/usr/local/bin/Rscript ...");

Of course, change the path to wherever it really is. You can check from a shell by running which Rscript.

If you really want to change the PATH for PHP, you should check this Stack Overflow post.

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.