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?

4
  • 1
    possible duplicate of How to run Ruby/Python scripts from inside PHP passing and receiving parameters? Commented Jun 10, 2015 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. Commented Jun 10, 2015 at 19:41
  • Looks like you're not allowed to read that file as the user running the PHP script. Commented Jun 10, 2015 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? Commented Jun 11, 2015 at 5:25

1 Answer 1

0
exec(rubyfile.rb);

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.