I have an R script that I need to execute on my PHP page. Here’s my code
exec("Rscript D:/webs/popdyn/SingleSpeciesLWR_2.r D:/webs/popdyn/hello.csv none");
I have 2 parameters here, 1st is my csv file and 2nd is none. It works well when I execute this in cmd, but in PHP it doesn’t work.
This is most likely a PATH issue. Check that Rscript.exe is in the PATH for your system environment, and not your local user environment.
Reason: When PHP runs exec, it run is the environment of the user of the loading application (Could be IIS, Apache or PHP, depending on your set up). You can find out which user and add the path to that user, or just add the path to the system environment. You can do this through the control panel (NOT command line – adds to local only!).
Alternatively, specify the full path to Rscript in the exec().