Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Rscript via php not working but works on terminal

  1. #1
    Join Date
    Aug 2009
    Beans
    27

    Question Rscript via php not working but works on terminal

    Hi,

    I have installed R on my server and have a problem with Rscript. basically when i use Rscript via terminal its working but the same exact code via php doesnt work.

    on terminal:

    Rscript file.R > file.csv

    WORKS!

    on php:

    shell_exec("Rscript file.R > five.csv");

    DOESNT work...

    tried:

    shell_exec("Rscript file.R 2>&1");

    and shows:

    Rscript: command not found

    located Rscript directory at /usr/bin/Rscript

    so i changed the code to:

    shell_exec("/usr/bin/Rscript file.R 2>&1");

    and got:

    sh: usr/bin/Rscript: No such file or directory

    made various variations to code thinking either i needed to make sure path to file is correct. tried both absolute and relative paths. nothing worked.

    any ideas? please help me. THANKS

  2. #2
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Rscript via php not working but works on terminal

    I guess the httpd (apache?) restricts what can be executed. Look in configuration settings for your web server.
    Last edited by schragge; February 11th, 2013 at 03:32 PM.

  3. #3
    Join Date
    Aug 2009
    Beans
    27

    Re: Rscript via php not working but works on terminal

    can you kindly point out what settings i should look for?

  4. #4
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Rscript via php not working but works on terminal

    I don't know. That was only a wild guessing on my part. I could be very well wrong. Maybe there is someting in the error_log of your web server?
    Last edited by schragge; February 11th, 2013 at 04:12 PM.

  5. #5
    Join Date
    Nov 2008
    Location
    Sheffield, UK
    Beans
    1,516
    Distro
    Ubuntu

    Re: Rscript via php not working but works on terminal

    has user www-data got access to
    /usr/bin/Rscript ?

    In my exec scripts I use a ' not " not sure if it matters
    & this


    sh: usr/bin/Rscript: No such file or directory

    is not the same as
    sh: /usr/bin/Rscript: No such file or directory

    Typo?

  6. #6
    Join Date
    Aug 2009
    Beans
    27

    Re: Rscript via php not working but works on terminal

    how can i check if www-data got access to /usr/bin/Rscript? if they dont, how can i give it access?

    i tried both:

    echo "usr/bin/Rscript 2>&1";
    print_r ( shell_exec('usr/bin/Rscript 2>&1'));
    echo "<br />";

    echo "/usr/bin/Rscript 2>&1";
    print_r ( shell_exec('/usr/bin/Rscript 2>&1'));
    echo "<br />";

    and they give:

    usr/bin/Rscript 2>&1 sh: usr/bin/Rscript: No such file or directory
    /usr/bin/Rscript 2>&1 sh: /usr/bin/Rscript: No such file or directory

    i really hope this can be resolved soon. thanks

  7. #7
    Join Date
    Nov 2008
    Location
    Sheffield, UK
    Beans
    1,516
    Distro
    Ubuntu

    Re: Rscript via php not working but works on terminal

    Code:
    sudo chmod 755 /usr/bin/Rscript
    Does that error (unsure about capital R)

    Unsure of php script but mine are along the lines of:
    Code:
    <?php
    shell_exec('/usr/bin/Rscript 2>&1');
    ?>

  8. #8
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Rscript via php not working but works on terminal

    Quote Originally Posted by megamonk View Post
    how can i check if www-data got access to /usr/bin/Rscript? if they dont, how can i give it access?
    I guess file permissions are ok, but there can be apparmor at play. If a confined process doesn't have access to a file, you'll get messages like
    Code:
    audit(1148420912.879:96): REJECTING x access to /bin/uname (sh(6646) profile /tmp/sh active /tmp/sh)
    either in /var/log/audit/audit.log or /var/log/messages

  9. #9
    Join Date
    Aug 2009
    Beans
    27

    Re: Rscript via php not working but works on terminal

    i have checked the permission of Rscript and its 0755.

    i dont know if this helps but in my windows box i had to add the path to R directory to the environment variables to get it working on the local instance of my site.

    on the ubuntu server.. i checked the $PATH (echo $PATH) when im using the terminal via ssh as:

    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

    but on php:

    using -> shell_exec('echo $PATH') outputs:
    /sbin:/usr/sbin:/bin:/usr/bin

    in both paths, i can see that the directory /usr/bin is present. does this make a difference? or is their something wrong here?

    about the capital "R", are you referring to the "Rscript" wording? if so i have checked using the terminal that using "rscript" (lowercase) doesnt work but "Rscript" works which suggest its case sensitive.

    ex:

    rscript blah.r <- doesnt work
    Rscript blah.r <- works

  10. #10
    Join Date
    Aug 2009
    Beans
    27

    Re: Rscript via php not working but works on terminal

    Quote Originally Posted by schragge View Post
    I guess file permissions are ok, but there can be apparmor at play. If a confined process doesn't have access to a file, you'll get messages like
    Code:
    audit(1148420912.879:96): REJECTING x access to /bin/uname (sh(6646) profile /tmp/sh active /tmp/sh)
    either in /var/log/audit/audit.log or /var/log/messages
    checked /var/log but cant find "messages" or "audit". since i tested it today i checked the latest changed/updated log file and the only thing that changed is "auth.log". checked it and nothing remotely similar to the error log you gave within the time frame of my test.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •