Sunday, May 19, 2024
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 1678  / 2 Years ago, sun, october 16, 2022, 9:20:39

I'm new to Ubuntu
I'm trying to execute an Rscript in PHP using exec. However it doesnt run.
When I run it from the terminal it executes perfectly.



This is the code I run from commandline:



/usr/lib/R/bin/Rscript /home/xin/Documents/ClassificationApp/ClassificationAllInOne.R "http://localhost/categorisation/public/classification/data/1423242832.json"


It works perfectly.



From searching around i can deduce it is a permissions issue as PHP/apache runs as www-data and Rscript is root.



I've tried a number of ammendments to the Sudoers file none of which worked:-



User_Alias WWW_USER = www-data
Cmnd_Alias WWW_COMMANDS = /usr/lib/R/bin/Rscript, /home/xin/Documents/Classifi$

WWW_USER ALL = (ALL) NOPASSWD: WWW_COMMANDS


This hasn't worked. I've spent a day messing around with various combinations. It's driving me mad.



Any inspiration would be most welcome



M


More From » command-line

 Answers
4

When debugging PHP code that executes external scripts (R, bash, ...) the easiest thing to do is to install php-cli



sudo apt-get install php-google-api-php-client 


php-cli means "PHP Command Line Interface". As the name suggests, it's is a way of using PHP from the terminal.



then execute the script using /usr/bin/php -q <?php YourPHPCodeHere; ?>



Alternatively, create a file that contains the PHP code:



#!/usr/bin/php -q
<?php
echo "Hello world...";
?>


then chmod +x szNameOfFile



and then just type ./szNameOfFile



If you don't want to type the full path to your PHP script, just create a bin directory in your home directory and copy all your script files there (this directory automatically gets added to the path after you exit and re-open your terminal)


[#21413] Monday, October 17, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mance

Total Points: 198
Total Questions: 105
Total Answers: 128

Location: South Georgia
Member since Mon, Aug 16, 2021
3 Years ago
mance questions
Wed, Jul 14, 21, 12:04, 3 Years ago
Tue, Jul 20, 21, 10:52, 3 Years ago
Thu, Sep 1, 22, 15:22, 2 Years ago
Sun, Jun 13, 21, 05:50, 3 Years ago
;