How to reboot server with PHP code?

Discussion in 'PHP' started by nice.wallpapers, Sep 9, 2008.

  1. #1
    Hi ,

    Just want to know how we can reboot linux server with php code.

    Thanks,
     
    nice.wallpapers, Sep 9, 2008 IP
  2. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #2
    I don't think it's possible unless you are running a vps/dedicated machine.

    Regards
     
    nabz245, Sep 9, 2008 IP
  3. nice.wallpapers

    nice.wallpapers Active Member

    Messages:
    142
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Hi,

    I think it is possible through php sodu but i need code :(

    Thanks,
     
    nice.wallpapers, Sep 9, 2008 IP
  4. wdillsmith

    wdillsmith Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If it is linux or unix, you should be able to execute the reboot command, assuming you have permission. I'm not what will happen to your script though once you do, as it'll probably be killed immediately.
     
    wdillsmith, Sep 9, 2008 IP
  5. nice.wallpapers

    nice.wallpapers Active Member

    Messages:
    142
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Hi,

    Please study sodu then you will understand , sodu gives root power to any thread on linux.

    I think i have to find solution my self.

    Thanks,
     
    nice.wallpapers, Sep 9, 2008 IP
  6. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You mean sudo. If the script is running as root you can exec("reboot");
     
    matthewrobertbell, Sep 10, 2008 IP
  7. nice.wallpapers

    nice.wallpapers Active Member

    Messages:
    142
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #7
    oh sorry i spelled it wrong it is "sudo" :)

    thanks for the info,
     
    nice.wallpapers, Sep 10, 2008 IP
  8. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #8
    Note: The below is dangerous if you're unsure what you're doing

    You'll need to visudo as root, add something like:
    user ALL=(ALL) NOPASSWD: /sbin/shutdown
    Code (markup):
    Then run:
    <?php
    `shutdown -r now`;
    ?>
    PHP:
    Never use nobody or apache. The script should run as user (replace into visudo code above) but that user shouldn't be shared by other scripts, i.e. nobody. If you run it as root, just the PHP code is required.

    Jay
     
    jayshah, Sep 10, 2008 IP