How do i connect php(with apache server) with rubygems in ubuntu

I am in need of using a ruby script for my website.I am very new to
ruby, and I only need to use single gem(anystyle-parser) for my ruby
script, and so I decided to use php to create the website.

My PHP code :

<?php if (isset($_POST["ref"])) { $reference=$_POST["ref"]; echo "OUTPUT :"; echo "
"; $cmd="ruby test.rb ".escapeshellarg($reference); echo system($cmd); } else {} My ruby code : require 'anystyle/parser' require 'rubygems' ref=ARGV[0] s=Anystyle.parse ref puts s Gem requirements: -anystyle/parser The ruby script script works fine in the terminal.But it is not working ,when called through the php(in the localhost). Somehow the apache server does not seem to recognize the functions related to the gem 'anystyle-parser'(I believe that there is some access problem between the webserver and the gem). So,should i have to make any changes in the apache config file to access the gem?Or should i have to specify the path of the gem in the ruby script or anywhere else? If none of the above is possible, then is there any way to execute the ruby script in the PHP wesite?