Hi,
I try to reboot my Ubuntu 16.04 through PHP.
I installed SSH2 extension, write code and it have a problem:
SSH connection: [OK]
Athentication: [OK]
Shell: [OK]
reboot -i
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-66-generic x86_64)
* Documentation: https://help.ubuntu.com/
332 packages can be updated.
4 updates are security updates.
Last login: Sun Mar 12 18:50:57 2017 from 192.168.80.137
]0;lam@lam: ~lam@lam:~$ reboot
Failed to set wall message, ignoring: Interactive authentication required.
Failed to reboot system via logind: Interactive authentication required.
Failed to start reboot.target: Interactive authentication required.
See system logs and 'systemctl status reboot.target' for details.
Failed to open /dev/initctl: Permission denied
Failed to talk to init daemon.
Then I use command line:
#chmod 777 /dev/initctl
It's work, Ubuntu reboot through PHP!!!!.
But after reboot, I try php code I gain, I show similar error above. I must #chmod 777 /dev/initctl again to keep it's work.
Please help me.
P/s: here my php code
<?php
echo "SSH connection: ";
if (!($resource=@ssh2_connect("192.168.80.137"))) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";
echo "Athentication: ";
if (!@ssh2_auth_password($resource,"lam","root")) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";
echo "Shell: ";
if (!($stdio = @ssh2_shell($resource,"xterm"))) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";
$command = "reboot\n";
fwrite($stdio,$command);
sleep(1);
while($line = fgets($stdio)) {
flush();
echo $line."<br />";
}
fclose($stdio);
?>
What I have tried:
Reboot my Ubuntu 16.04 through PHP.