Blog

Wake on LAN and shutdown on php

posted 16 Jul 2011 00:49 by Puneet Vyas

Most of the motherboards now come with a nifty function of wake on Lan. This allows a computer to be woken up by a network message. Typical use case scenario is in Home media server setup. The media player is usually in the living room and the media server in the back room. Leaving the server on always uses up un necessary power. So an easy way to wake up your server is either from your mobile device (phone, ipad etc.). Here is how I achieved this.

I have an Asus P5VDC-MX motherboard with inbuilt LAN. 

1) Upgraded the BIOS with the newest firmware. Using ASUS support software AFUDOS.exe on a bootable CD. I made bootable CD using Flash CD creator. Alternatively also available here
2) Enabled WOL on the motherboard. Finding the bios menu for WOL was a bit tricky. It was here : Power>APM configuration>Resume on PME
3) Followed this post on Ubuntu forum to setup WOL on Ubuntu 10.04. Only addition was installing the ethtool.
4) Downloaded WakeOnLAN from ReadPixel on my mac. 
5) Downloaded NetAwake on my iPhone.
6) Found the MAC address of my ubuntu server ethernet card using ifconfig. Setup both the applications with address to server. 
Thats it.. All set to use WOL on Ubuntu media server.

Another, issue was shutting down my server with a remote device. For that, I wrote a short php script and installed it on the ubuntu server. Now I could access this page anywhere on my local network to initiate a shutdown.

<html>
    <head>
        <title>I am going down</title>
    </head>
    <body>
        <h1><?php echo shell_exec("hostname")?></h1>
        <h2><?php echo shell_exec("uptime")?></h2>
        <form name="password" action="shutme.php" method="post">
            <input name="shutdown"  type ="submit" value="shutdown">
        </form>
        <?php
            if(isset($_REQUEST["shutdown"]))
               $output = shell_exec("sudo shutdown -h now webuser did it");
        ?>
     </body>
</html>

and added following line to sudoers file :

www-data localhost=(root)NOPASSWD:/sbin/shutdown

to run the shutdown command from the php script as sudo.

Thanks to the post on breeze.

1-1 of 1