PHP as Root

  • camperjohn
  • Guru
  • Guru
  • User avatar
  • Posts: 1127
  • Loc: San Diego

Post 3+ Months Ago

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 ?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6251
  • Loc: Seattle, WA

Post 3+ Months Ago

Wouldn't you need to log in to run PHP as root anyways? :scratchhead:
  • camperjohn
  • Guru
  • Guru
  • User avatar
  • Posts: 1127
  • Loc: San Diego

Post 3+ Months Ago

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.
  • X3ndou
  • Proficient
  • Proficient
  • User avatar
  • Posts: 263
  • Loc: New Jersey

Post 3+ Months Ago

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.
  • sandy_j_sam
  • Newbie
  • Newbie
  • sandy_j_sam
  • Posts: 9

Post 3+ Months Ago

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: No registered users and 145 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.