I am trying to run a ruby script from php (browser) that requires some gems. VPS: CentOS, PHP5, ruby2.0.0, using RVM. I reach the server via PUTTY and I ran the php code from browser.
So when I run this:
<?php
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "./error-output.txt", "a")
);
$process = proc_open('ruby /home/balint/test.rb', $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], 'hello world');
fclose($pipes[0]);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
$return_value = proc_close($process);
echo "command returned $return_value
";
}
?>
And the test.rb script includes only puts "xxx" then I get the output on my screen as xxx.
However, when I include some gems like require 'nokogiri' I get this in the error log:
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- nokogiri (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/balint/test.rb:5
This is working fine directly from shell.
ruby -v:
ruby 2.0.0p643 (2015-02-25 revision 49749) [x86_64-linux]
which ruby:
/usr/bin/ruby
gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 2.0.0 (2015-02-25 patchlevel 643) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/balint/.rvm/gems/ruby-2.0.0-p643
- RUBY EXECUTABLE: /home/balint/.rvm/rubies/ruby-2.0.0-p643/bin/ruby
- EXECUTABLE DIRECTORY: /home/balint/.rvm/gems/ruby-2.0.0-p643/bin
- SPEC CACHE DIRECTORY: /home/balint/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /home/balint/.rvm/rubies/ruby-2.0.0-p643/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/balint/.rvm/gems/ruby-2.0.0-p643
- /home/balint/.rvm/gems/ruby-2.0.0-p643@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["https://rubygems.org/", "http://rubygems.org"]
- REMOTE SOURCES:
- https://rubygems.org/
- http://rubygems.org
- SHELL PATH:
- /usr/local/jdk/bin
- /home/balint/.rvm/gems/ruby-2.0.0-p643/bin
- /home/balint/.rvm/gems/ruby-2.0.0-p643@global/bin
- /home/balint/.rvm/rubies/ruby-2.0.0-p643/bin
- /home/balint/perl5/bin
- /usr/local/bin
- /bin
- /usr/bin
- /usr/local/sbin
- /usr/sbin
- /sbin
- /home/balint/.rvm/bin
- /usr/local/bin
- /usr/X11R6/bin
- /home/balint/.rvm/bin
- /home/balint/bin
echo $PATH
/usr/local/jdk/bin:/home/balint/.rvm/gems/ruby-2.0.0-p643/bin:/home/balint/.rvm/gems/ruby-2.0.0-p643@global/bin:/home/balint/.rvm/rubies/ruby-2.0.0-p643/bin:/home/balint/perl5/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/balint/.rvm/bin:/usr/local/bin:/usr/X11R6/bin:/home/balint/.rvm/bin:/home/balint/bin
According to the log it's looking in the 1.8 folder. But there is no other folder in usr/lib/ruby/site_ruby/
than 1.8. And I also don't understand why it's working in shell and why it's not from the browser.
Can someone put me in the right direction here?