0

Ruby is installed here:

.rvm/rubies/ruby-2.2.1/bin

Ruby script:

puts "Hello world"

Php script:

<?php
    $cmd = "ruby /home/balint/rubytest.rb";     
    echo system($cmd);
?>

I can run sudo php /home/name/public_html/phprubytest.php from CLI but not from the browser.

I reach the server via Putty and use Filezilla to put all my website-related files to the public_html folder.

I logged out the error and it turned out I have a permission error:

ruby: Permission denied -- /home/balint/rubytest.rb (LoadError)

This means as a user running the php script from the browser I have no access to that directory on the server.

Any ideas?

erdomester
  • 11,789
  • 32
  • 132
  • 234
  • 1
    possible duplicate of [How to run Ruby/Python scripts from inside PHP passing and receiving parameters?](http://stackoverflow.com/questions/4619996/how-to-run-ruby-python-scripts-from-inside-php-passing-and-receiving-parameters) – Reinstate Monica -- notmaynard Jun 10 '15 at 19:37
  • That is a fantastic tutorial to send and receive data and that's where I come from. I tried it, received `command returned 1` message so I decided to try out the simple script. And here I am now. – erdomester Jun 10 '15 at 19:41
  • Looks like you're not allowed to read that file as the user running the PHP script. – tadman Jun 10 '15 at 21:11
  • That's right. It has -rw-rw-r-- permissions. What I did is that I copied it into the public_html folder where I have permission to run it. However, in order to run the ruby script now from php I should add the absolute path of all the gems that I use. What's the better way here, solving the permission issue or setting path for all gems? – erdomester Jun 11 '15 at 05:25

1 Answers1

0
exec(rubyfile.rb);

Just add this code and it will execute your ruby file.

Akif Hazarvi
  • 47
  • 1
  • 11