say the script is

http://www.mysite.com/runruby.php

<?php
   shell_execute('ruby /home/rubysript/script.rb');
   exit;

If I run it through http, it is run as apache user. And the ruby script is not executed.

But if in the shell command, I run

php runruby.php

It is run as the user which is my shell account. And the ruby script is executed.

So how can I make it work by http request to http://www.mysite.com/runruby.php.

Thanks!

    Probably the simplest thing would be to add read permission to the script (and read+execute for its containing directories) to all (or group if applicable) so that the web server user can read it. Also, if the web server user's path setting does not include the ruby executable directory then you may need to specify the full path to ruby.

      the ruby script has the 644 permission, and i gave the full path already.

      if i run shell_execute('whoami'), i can run both from http or shell.

      but if run shell_execute('ruby /home/rubysript/script.rb');

      I can only run from shell not http.

        shell_exec('usr/local/bin/ruby /samples/sample.rb >> logfile');

        I think in our server set up the user "apache" is not permitted to run "usr/local/bin/ruby", or "usr/bin/php".

        By the way, I mean shell_exec in my above threads.

        With this set up, any solutions for my issue?

        Thanks!

          I can use shell_exec("sudo ...")

          To change the user and read a text file for the password of that user and then run /usr/bin/php or /usr/local/bin/ruby as that user. But if I don't have to, I don't want to put password in a plain text file.

          Any other solutions?

            OK, it is solved.

            User "apache" has no permission to run /usr/bin/php or /usr/local/bin/ruby. But I can make the php and ruby script executable. Instead of shell_exec("/usr/bin/php /mysite/my.php"), I can call shell_exec("/mysite/my.php").

            Thanks!

              as a matter of fact, I can run shell_exec('/home/ruby/myruby.rb') through http request after I made script myruby.rb executable, but I still cannot run shell_exec('/home/mysite/myphp.php') through http request even after I made script myphp.php executable. So I used a sh script instead of executable php script. And it works.

                Write a Reply...