PHP as Root

  • camperjohn
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 28, 2004
  • Posts: 1127
  • Loc: San Diego
  • Status: Offline

Post April 26th, 2010, 11:45 pm

does anyone know how to run php as root temporarily?

I have some install script I want to write and dont want to login ssh and run "php script.php" I would rather run them from a browser, then delete them when done.

Ideas ?
Upload video and picture galleries at http://www.bodydot.com?post+upload+video+picture+gallery
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post April 26th, 2010, 11:45 pm

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Joined: Sep 22, 2003
  • Posts: 6128
  • Loc: Seattle, WA
  • Status: Offline

Post April 27th, 2010, 9:16 am

Wouldn't you need to log in to run PHP as root anyways? :scratchhead:
The Beer Monocle. Classy.
  • camperjohn
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 28, 2004
  • Posts: 1127
  • Loc: San Diego
  • Status: Offline

Post April 27th, 2010, 10:31 am

Yeah that's what I want to avoid.

I found this:

Code: [ Select ]
<?php
shell_exec('sudo -u root -S command_goes_here < /home/$user/dir/passfile');
?>
  1. <?php
  2. shell_exec('sudo -u root -S command_goes_here < /home/$user/dir/passfile');
  3. ?>


Or this...

Code: [ Select ]
<?php
$password = $_GET['password'];
shell_exec('sudo -u root -S command_goes_here < $password');
?>
  1. <?php
  2. $password = $_GET['password'];
  3. shell_exec('sudo -u root -S command_goes_here < $password');
  4. ?>


Then I can just make a temporary file with the password, or enter it from an <INPUT> tag and do what I need to do. Then delete the temp file when work is done.
Upload video and picture galleries at http://www.bodydot.com?post+upload+video+picture+gallery
  • X3ndou
  • Proficient
  • Proficient
  • User avatar
  • Joined: Nov 06, 2004
  • Posts: 263
  • Loc: New Jersey
  • Status: Offline

Post April 30th, 2010, 8:17 pm

You shouldn't have to run any web-related php scripts as root, ever. If you've written one that requires root you're doing it wrong.

By the way, never, ever take passwords through an http get. Also if you're gonna pass some user input to shell_exec you'd better sanitize it.
"On the day *I* go to work for Microsoft, faint oinking sounds will be heard from far overhead, the moon will not merely turn blue but develop polkadots, and hell will freeze over so solid the brimstone will go superconductive." -Eric S. Raymond
  • sandy_j_sam
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jul 26, 2010
  • Posts: 9
  • Status: Offline

Post July 28th, 2010, 10:52 pm

Hi, As we know that php is a server side scripting language, means no way that, it's program run without server, i.e on local browser, then you first install server, like Apache, see them
[WAMP] => window + Apache Server + MySql + php.
Now I mention here Editor like Adobe Dream Weaver, where you write code having extension is .php,
now you save it in root folder
Path : C:/D:/E:/F:/ = >wamp => www => you create folder(Like php app.) =>php_script.php

and still you face some problem then just mention here.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: ScottG and 184 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.