Reboot From PHP Page


<?php
	//----- DO THE REBOOT -----
		//THIS SUDO COMMAND NEEDS TO BE AUTHORISED FOR APACHE TO USE IT IN THE FILE: sudo nano /etc/sudoers
		//	# Special for this system - let apache run exes we use in the web interface
		//	www-data ALL=NOPASSWD: /sbin/reboot
	echo '<pre>';
	system("(sleep 2 ; sudo /sbin/reboot ) > /dev/null 2>&1 & echo $!");
	echo '</pre>';
?>

The sleep causes a 2 second delay before its actions.

The "> /dev/null 2>&1 & echo $!" causes the system command to return immediately and for the command to be issued in the background, allowing the page to load before the reboot actually occurs.

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

  1. Chris

    4 years ago

    Remove the ‘echo’ in /dev/null 2>&1 & echo $!”);

    Otherwise the process # is displayed on the webpage.

Comments

Your email address will not be published. Required fields are marked *