How to run R through PHP with exec?
- by dkar
I am going to ask something, that I know that it has been asked already some times. But since, all of the past posts are quite old and none of them answer my problem..I try again.
I am completely new in R language and relative new in php.
What I want to do is to use the exec() function from php in order to execute a R script.
Most of the people here will start talking about rapache, rserve and I don't know what else..but since I am not familiar with all these technologies, I prefer just using exec.
The code I will show here is working just fine when I run it with Rscript from the terminal.
# R script
png("temp.png")
plot(5,5)
dev.off()
But when I try to run it either with Rscript or with R CMD BATCH from PHP, like this:
echo exec("Rscript my_rscript.R"); //OR
//echo exec("R CMD BATCH my_rscript.R");
I get nothing back.
I have checked if exec() function is available and if it works. Everything is ok with this.
I read also, that I might have to change the permissions of the webserver...but I don't know how to do this in mamp.
I hope I am clear with my problem and someone can help.
Thanks
Dimitris