Page 1 of 1

use PHP to restart the linux machine

Posted: Wed Jun 04, 2003 2:29 pm
by shawnzhou888
I tried to execute the following command to retart the linux machine but failed. Any idea? I tried other commands like exec, system, etc. All don't work.

<?php
shell_exec("shutdown r now");
?>

Posted: Wed Jun 04, 2003 2:32 pm
by nielsene
You need to have superuser permission to issue the shutdown command. PHP runs as the webserver (typically www-data or nobody) and has extremely restricted permissions.

Posted: Wed Jun 04, 2003 2:37 pm
by shawnzhou888
Thanks for your quick answer, Eric. Does that mean the Apache web server must run as a root to enable the shutdown command?

Posted: Wed Jun 04, 2003 2:38 pm
by nielsene
Yes, but I would very strongly recommend against doing that.

Posted: Wed Jun 04, 2003 2:42 pm
by shawnzhou888
I know it's dangrous. But what I am doing is an element management system. So the restart function is needed.

Posted: Wed Jun 04, 2003 2:52 pm
by volka
take a look at http://www.courtesan.com/sudo/
and avoid apache running as root