Author Topic: [SOLVED] PHP "system" command as root?  (Read 1913 times)

Offline Socratea

  • Full Member
  • ***
  • Posts: 156
  • Noob is as noob does
[SOLVED] PHP "system" command as root?
« on: July 28, 2011, 08:47:46 AM »
Hi Experts,

I'm building a server in which I want to use R (statistics program) to generate graphs based on user input.
I have an R script which creates a graph and saves it as jpeg, now I want to run it on my server (localhost for now, I'm testing).
Thus I want to create a jpeg (called test.jpeg below) in my /var/www/html/test/ folder which is then displayed on a webpage.

In general this is what I want to do;

Code: [Select]
<?php 
if(isset($_POST['analyses'])){
$command='R CMD BATCH testscript.r';
system($command);
echo 
'<img src="test.jpeg" width="458" height="458" alt="pic" />';
}

 
?>

However of course the jpeg cant be written to  /var/www/html/test/ without root privileges.
After conducting some web searches I found this recommendation - I should put the bash command:

echo "PASSWORD" | sudo -u root -S COMMAND

in the php system function.

However PCLOS does not use sudo. Now I could setup a sudoers list but I'd rather stick to the philosophy of PCLOS.

Does anybody have any tips on how I can solve this?

Your time is greatly appreciated,

« Last Edit: July 29, 2011, 03:37:22 AM by Socratea »

Only those that choose a different path from
the others become great and infinite.

.

Offline Socratea

  • Full Member
  • ***
  • Posts: 156
  • Noob is as noob does
Re: [SOLVED] PHP "system" command as root?
« Reply #1 on: July 29, 2011, 03:42:18 AM »
I should have just gone to bed before I asked that question.  ::)

This can ofcourse be solved by simply setting file permissions.

Run <?php exec('whoami') ?> to find out who you are, for me this was non-surprisingly 'apache'

Then remove all permissions of website folder
chmod o-rwx *

Then set user to owner
chown apache *

Then give user read,write and execute permissions
chmod u=rwx *


Done.

Only those that choose a different path from
the others become great and infinite.

.

Offline Wildman

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 7556
  • Symphony for a Unstrung Tongue
Re: [SOLVED] PHP "system" command as root?
« Reply #2 on: July 29, 2011, 03:54:38 PM »
 8) 8)
Happiness is not having what you want, but wanting what you have!

Joe Gable, "Joble" Was my Friend..
Dave "Exwintech" has also gone on...
Linux Counter #288984